我想在不创建自定义单元类的情况下创建自定义单元格。我知道这是可能的。我在storyboard中创建了一个带有标签的原型单元格的tableviewcontroller。在attibutes中,我设置了单元名称“mycell”。而我使用的代码是:CustomCell without storyCell class with storyboard
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ static NSString *CellIdentifier = @"mycell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];}
UILabel *title = (UILabel*) [cell viewWithTag:1];
title.text = @"Hi";
return cell;
}
但是,当我的应用程序来看,我看到的只是一个空表,而我的标签细胞。 (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {return 1;} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {return 5; }
谢谢。
你看到5个部分? – iOSGuru248 2013-04-24 15:25:41
我复制了你的代码,它对我来说工作得很好。您是否将控制器设置为表视图的数据源?你是否将IB中表视图控制器的类更改为这个类(你的发布代码在哪里)? – rdelmar 2013-04-24 15:39:02
我正确设置了数据源和委托,并将故事板中表格视图控制器的类更改为此类。但是这段代码仍然不适合我。 – user2136333 2013-04-24 15:51:47