use*_*099 12 objective-c uitableview ios
在我的应用程序中,我想在iPad中显示多列tableView.
所以,我使用了来自MultiColumn TableView的cocoa控件
它适用于我,但我想以交替颜色显示行.
为此,我无法找到我为其更改代码的位置.
帮我解决这个问题.
Dha*_*ngh 44
请尝试使用它,它会工作正常..
- (void)tableView: (UITableView*)tableView willDisplayCell: (UITableViewCell*)cell forRowAtIndexPath: (NSIndexPath*)indexPath
{
if(indexPath.row % 2 == 0)
cell.backgroundColor = [UIColor redColor];
else
cell.backgroundColor = [UIColor whiteColor];
}
Run Code Online (Sandbox Code Playgroud)
使用indexPath cellForRowAtIndexPath
来获得所需的结果.
if( [indexPath row] % 2){
cell.backgroundColor=[UIColor whiteColor];
}
else{
cell.backgroundColor=[UIColor purpleColor];
}
Run Code Online (Sandbox Code Playgroud)
您将在实现该类的类中使用此委托方法 UITableViewDelegate
试试这个代码::
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
.......
if (indexPath.row % 2 == 0) {
cell.backgroundColor = [UIColor lightGrayColor];
}
else
{
cell.backgroundColor = [UIColor darkGrayColor];
}
.......
return cell;
}
Run Code Online (Sandbox Code Playgroud)
希望,它会帮助你.
谢谢.
首先,您需要对每行进行模块化.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
.......
if (indexPath.row % 2 == 0) {
cell.backgroundColor = [UIColor lightGrayColor];
}
else
{
cell.backgroundColor = [UIColor darkGrayColor];
}
....
return cell;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
18608 次 |
最近记录: |