Search code examples
iosobjective-cipaduisplitviewcontroller

HowTo? UISplitViewController TableCell Image


I would like to know if it is possible to assign some kind of icon/image to the navigation table cells on the left side of the UISplitViewController in an iPad App.

e.g. an image next to row 1...

http://www.cre8ive.kr/blog/wp-content/uploads/SplitViewTest_03.png

I am trying to approach this with editing the

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; 

method.

Here's what I got

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];    
    }
    cell.textLabel.text = [NSString stringWithFormat:@"%i", indexPath.row +1];  
    //Let the magic happen here :D
    UIImage *image = [UIImage imageNamed:@"deviantart_dark.png"];
    //Nothing changes :(
    [[cell imageView] setImage:image];
    return cell;
}

Any ideas?


Solution

  • You could use the below code,

    cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage:imageNamed:@"deviantart_dark.png"]];