Description: Note that some of the trivia of learning iOS, some in the present seems very simple childish, but the right to learn footprints it!
1. When defining the UITableViewCell, the component can be added directly, or it can add to the Contentview
[Self addsubviews:mybtn]; [Self.contentview ADDSUBVIEWS:MYBTN];
But it's best to add it in Contentview because Contentview can define a lot of things.
2. For pull-down refresh and pull-up loading, it can be used as a third-party framework Mjrefresh, address in
Https://github.com/CoderMJLee/MJRefresh
Select part of the code description.
1- (void) Viewdidload {2 [Super Viewdidload];3 //Pull-up loading4 [self refreshbottomdata];5 }6 7 //Drop-down refresh8-(void) refreshbottomdata{9 [Self.tableview addfooterwithtarget:self Action: @selector (footerrereshing)];TenSelf.tableView.footerPullToRefreshText =@"Pull-up loading"; OneSelf.tableView.footerReleaseToRefreshText =@"Release Load"; ASelf.tableView.footerRefreshingText =@"Loading in ..."; - } - the-(void) footerrereshing{ - //add false data added when refreshing - for(inti =0; i<5; i++) { -[Self.dataarray Insertobject:self.insertdataarray[i] Atindex:0]; + } - + //refresh after 1 seconds ADispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (1.0* nsec_per_sec)), Dispatch_get_main_queue (), ^{ at //Refresh Table - [Self.tableview Reloaddata]; - - //(preferably called after refreshing the table) call endrefreshing to end the refresh State - [Self.tableview headerendrefreshing]; - }); in}
In real-world development, when adding data when refreshing, you can use paging, which is well implemented in the background. Then load more data according to PageNo.
3. With regard to the layering of UIView, if you want to move component A to the topmost level, there are two ways of thinking: ① move a directly to the top, ② move the other components to the bottom layer.
As in a uiview, there are 3 components, VIEWA,VIEWB,VIEWC. Now you want to move the Viewa to the top level.
For ①, you can use Bringsubviewtofront, which is to move to the top level
[Self Bringsubviewtofront:viewa];
For ②, you can use Sendsubviewtoback, that is, to move to the underlying
[Self SENDSUBVIEWTOBACK:VIEWB]; [Self SENDSUBVIEWTOBACK:VIEWC];
However, methods ① and ② are defective, and when Viewa, VIEWB, and VIEWC are initialized by lazy loading, the view is not displayed. That is, Viewa, VIEWB, VIEWC are not displayed at all.
You need to use it now.
-(void) Insertsubview: (UIView *) View Atindex: (nsinteger) index; // the smaller the index, the more the view is below.
So we can solve this, when adding VIEWB and VIEWC,
[Self InsertSubview:self.viewB atindex:0]; [Self InsertSubview:self.viewC atindex: 0];
This method does not need to be lazy to load the tube components, the effect is the same as Sendsubviewtoback.
4. A very good debugging skills, the usual debugging needs their own break point, step by step, see where will crash. The following method will jump directly to the broken line, very useful.
Click the plus sign in the lower left corner of the debug interface,-->add Exception Breakpoint
The effect is as follows:
Can.
The difference between 5.UITabBarController and Uinavigationcontroller
1 //setting up a child controller2Uiviewcontroller *first =[[Uiviewcontroller alloc]init];3First.title =@" First";4Uiviewcontroller *second =[[Uiviewcontroller alloc]init];5Second.title =@"Second";6Uiviewcontroller *third =[[Uiviewcontroller alloc]init];7Third.title =@"Third";
Then you can see the difference when you add a sub-controller
Uinavigationcontroller *navcontroller = [[Uinavigationcontroller alloc]initwithrootviewcontroller:first];[ Self Addchildviewcontroller:navcontroller];
Directly added is this
// the way to trouble . [self addchildviewcontroller:first]; [Self addchildviewcontroller:second]; [Self addchildviewcontroller:third]; // or can be used in a simple way self.viewcontrollers = @[first,second,third];
If you want the navigation bar to have the left and right baritem, you can set this
1 uibarbuttonitem *leftbaritem = [[Uibarbuttonitem Alloc]initwithbarbuttonsystemitem: Uibarbuttonsystemitemreply target:self Action:nil]; 2 Uibarbuttonitem *rightbaritem = [[Uibarbuttonitem Alloc]initwithbarbuttonsystemitem: Uibarbuttonsystemitemaction target:self Action:nil]; 3 first.navigationItem.leftBarButtonItem = Leftbaritem; 4 first.navigationItem.rightBarButtonItem = Rightbaritem; 5 Uinavigationcontroller *navcontroller = [[Uinavigationcontroller Alloc]initwithrootviewcontroller: First]; 6 [self addchildviewcontroller:navcontroller];
6. Touch the event, the following is the trigger event when touching the screen. This event is triggered whenever the screen is clicked.
-(void) Touchesbegan: (Nsset *) touches withevent: (uievent *)event{ // The method to execute [self todrawsth];}
7.valueForKeyPath can find some values in the array, such as
1Nsarray *testarray = [Nsarray arraywithobjects:@"2.0",@"2.3",@"3.0",@"4.0", nil];2 //to find the array and3NSNumber *sum = [Testarray valueforkeypath:@"@sum. Floatvalue"];4 //to find the average of all the data in the array5NSNumber *avg = [Testarray valueforkeypath:@"@avg. Floatvalue"];6 //to find the largest value in an array7NSNumber *max = [Testarray valueforkeypath:@"@max. Floatvalue"];8 //to find the smallest value in an array9NSNumber *min = [Testarray valueforkeypath:@"@min. Floatvalue"];
8.CADisplayLink can periodically invoke the @selector method inside it, such as:
1 self.link = [cadisplaylink displaylinkwithtarget:self selector: @selector (tododrawline)]; 2 // Frameinterval Change the number of running frames per second, equal to 2 to run once every other frame 3 3 ; 4 [Self.link addtorunloop:[nsrunloop Mainrunloop] formode:nsdefaultrunloopmode];
And then you don't need to destroy it.
= nil;
When the Cadisplaylink object is add to Runloop, the system periodically executes the method in @select, and after the invalidate operation, the Cadisplaylink object is removed from the Rnuloop, @ The selector call will also stop.
For Frameinterval
The default refresh rate for iOS devices is 60Hz, so Cadisplaylink's @selector default call cycle is 60 times per second. This cycle can be set with Frameinterval, Cadisplaylink @selector the number of calls per second =60/frameinterval. For example, when Frameinterval is set to 2, the call becomes 30 times per second.
9. How can I improve the smoothness of my app? (This turn from leaf isolated city ___)
You can use instrument to find all the view,layer that do not need to be transparent but transparent, and make it opaque.
Select Product-->profile
With color blended Layers selected,
In the case of Weibo clients, the following occurs
Red or crimson is the transparent layer and view, which is the reason for slowing down the flow of the app, as modified by the situation.
iOS work notes (vii)