简短实用的Objective-C代码段? [英] Short and useful Objective-C snippets?

查看:119
本文介绍了简短实用的Objective-C代码段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自XCode 4开始,现在有一个代码片段"部分,该部分在键入时通过自动完成功能提供片段.我会对大家都存储在其中的摘要非常感兴趣.哪些摘要可为您节省最多的时间(以及原因)?

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. What snippets save you the most time (and why)?

请仅发布实际代码段(表示没有尖刻的不需要臭皮的代码段",也没有我喜欢执行< XYZ>"的代码段),并且仅发布了简短而甜美(即最多不超过20行...).如果摘要没有明显用处,还请说明您认为它为何有用. ;)

Please only post actual snippets (meaning no snarky "don't need no stinkin' snippets", and no "i love snippets that do <XYZ>"), and only snippets that are short and sweet (i.e. no more than ~20 lines at the most...). If a snippet is not obviously useful, also explain why you think it is. ;)

推荐答案

我不认为这很重要,但是每当在任何视图控制器中添加UITableView时,我总是使用此代码段.

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 ;
}

如果不使用UITableViewController来显示表内容,则

非常方便.

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

这篇关于简短实用的Objective-C代码段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆