【发布时间】:2010-01-11 08:27:19
【问题描述】:
我知道如何更改导航栏标题的颜色,但是当我编写此代码时:
UILabel * label = [[[UILabel alloc] initWithFrame:CGRectMake(0,0,45,45)] autorelease];
label.textColor = [UIColor yellowColor];
label.backgroundColor=[UIColor clearColor];
self.navigationItem.titleView = label;
label.text=@"Title"; //CUSTOM TITLE
[label sizeToFit];
我希望我的导航栏显示单元格的标题,而不是自定义标题。
这是我的表格视图代码:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return ghazalList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [ghazalList objectAtIndex:row];
return cell;
}
【问题讨论】:
-
你的意思是你想让导航栏的标题在一个单元格被选中时改变?
-
没有。当我想更改标题颜色并编写此代码时 label.text=@"Title";此代码更改了我选择的单元格标题.. 我只想更改颜色而不是标题
-
如果你不想要自定义标题,那么不要写
label.text=@"Title"; //CUSTOM TITLE??我想我没有正确理解你...... -
OK 看假设,我们有表格视图和 5 个单元格,每个单元格都有一个特定的标题 Cell 1 / Cell 2 / Cell 3 等等......现在我想改变我的导航栏的颜色AnotherViewController 不是 RootViewController .. 所以当我使用该代码时,我的标题更改为 @"TITLE" 。例如,当我选择 CELL 2 / 我的 AnotherView 控制器的标题变为 CELL 2 时。如何在不更改单元格标题的情况下更改标题颜色?当我写这段代码时:label.text=@"Title";我 anotherviewController 的标题更改为 TILTE 。我不想根据单元格标签更改我的标题。只是颜色。
标签: ios objective-c uitableview