Momi Momi - 2 months ago 6
iOS Question

change navigation bar title's color

I know how to change the color of my navigation bar title but when I write this code:

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];


I want my navigation bar to show the cell's title, not custom title.

Here is my table view code:

-(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;
}

Answer

@Adam :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (!anotherViewController) {
    anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherViewController" bundle:nil];
    anotherViewController.navigationItem.title=[ghazalList objectAtIndex:indexPath.row];
    [self.navigationController pushViewController:anotherViewController animated:YES];
    [anotherViewController loadGhazal:indexPath.row];

}else {
    [anotherViewController loadGhazal:indexPath.row];
    anotherViewController.navigationItem.title=[ghazalList objectAtIndex:indexPath.row];
    [self.navigationController pushViewController:anotherViewController animated:YES];  
}

}

i creat a poem application so , i have 495 cell and 495 HTML file [poems] . each cell [POEM 1 to 495] has a special pooem . everything works fine but , this damn title color drive me crazy ... i put your code the color had changed but the title changed to Poem 5 !

Comments