Col*_*lin -2 objective-c textfield uitableview ios
在我的应用程序中,我想通过按数字顺序添加数字来显示表视图中有多少个单元格.例如,我希望表视图中的第一个单元格旁边有一个1,而第二个单元格旁边有一个2.
谢谢!
你可以在你的tableView:cellForRowAtIndexPath:方法中做这样的事情
cell.textLabel.text = [NSString stringWithFormat:@"%i", indexPath.row+1];
Run Code Online (Sandbox Code Playgroud)
编辑:
然后确保执行以下操作:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10; <<<<====specify here the number of rows to be displayed.
}
Run Code Online (Sandbox Code Playgroud)
附录:
如果您的标签中已存储了某些内容并且仍想存储数字,请尝试执行以下操作:
在故事板中,单击单元格,然后将样式更改为" Subtitle ".
然后回到表视图控制器,将以下行添加到上述方法:
cell.detailTextLabel.text = [NSString stringWithFormat:@"%i", indexPath.row+1];
Run Code Online (Sandbox Code Playgroud)
所以现在你有两个标签,一个是你想要存储你的字符串的标签,另一个标签是你所讨论的行数.
添加截图:

| 归档时间: |
|
| 查看次数: |
1832 次 |
| 最近记录: |