2011-09-21 96 views

回答

0

假設你已經保存你的價值觀,你是在某種NSArray的或其他類型的數據源(我要去承擔的NSArray)的顯示,那麼你可以做這樣的事情:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *selection = [myArray objectAtIndex:indexPath.row]; 

    if ([selection isEqualToString:@"Apple"]) 
    { 
     [myImageView setImage:[UIImage imageNamed:@"Apple.png"]]; 
    } 
    elseif ([selection isEqualToString:@"Orange"]) 
    { 
     [myImageView setImage:[UIImage imageNamed:@"Orange.png"]]; 
    } 
} 
0

我爲你回答了這個問題。

Here is the SO question

這將是一個好主意,如果你仍然需要一個UITableView幫助到同樣的問題作出迴應與評論。

這是從另一個問題的答案。


要麼設置cell.imageView.highlightedImage,或在didSelectRowAtIndexPath方法方法中,從cell.imageView.image零到某些改變[UIImage的imageNamed:@ 「myImage.png」]:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *kCustomCellID = @"com.me.foo.cell"; 
    UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCustomCellID] autorelease]; 
    cell.textLabel.highlightedTextColor = [UIColor blueColor]; 
    cell.imageView.image = nil; 
    cell.imageView.highlightedImage = [UIImage imageNamed:@"myImage.png"]; 
    return cell; 
} 

- (void)tableView:(UITableView *)tableView willDisplayCell:(iPadRootViewControllerTableCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { 
    cell.imageView.contentMode = UIViewContentModeScaleAspectFit; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    // Do this if you didnt set the highlightedImage in cellForRowAtIndexPath 
    // [self tableView:tableView cellForRowAtIndexPath:indexPath].imageView.image = [UIImage imageNamed:@"myApple.png"]; 
} 

編輯(添加其他問題的意見回答):

從一個行的一個數組得到一個特定的項目,只需使用indexPath.row作爲objectForIndex您的陣列。

0

大廈關閉的Thuggish Nugget's answer,你可以納入選擇名稱權成圖像串:

NSString *selection = [myArray objectAtIndex:indexPath.row]; 
[myImageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@.png", selection]]]; 

而且你可以凝結下來成一行。

+0

非常感謝。你是超級有用的! – Brandon

相關問題