问题描述
自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代码段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!