Short and useful Objective-C snippets?

前端 未结 9 884
慢半拍i
慢半拍i 2021-01-30 07:17

Since XCode 4, there is now a Code Snippets section which offers the snippets via auto-complete when typing. I\'d be very interested in snippets you all have stored in there. Wh

9条回答
  •  温柔的废话
    2021-01-30 07:48

    I don't if this counts but I always use this snippet whenever I add a UITableView in any of my view controllers.

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *cellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if(cell == nil)
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
                                          reuseIdentifier:cellIdentifier];
                // Do something here......................
        }
        // Do something here too .........................
        return cell;
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return ;
    }
    
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return ;
    }
    

    its quite handy if you are not using a UITableViewController to show table contents.

提交回复
热议问题