2011-10-28 23 views
0

我的信息2個陣列我通過以下加載在到的UITableView控制:負載在一個小區的UITableView的圖像 - 的xcode

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    if(indexPath.section == 0) 

     cell.textLabel.text = [arryTableData objectAtIndex:indexPath.row]; 

    else 
     cell.textLabel.text = [arryTableActions objectAtIndex:indexPath.row]; 
    cell.accessoryType = UITableViewCellAccessoryNone; 
    return cell; 
} 

我想頂端陣列(arryTableData),這是在第一個單元格下方顯示該位置的圖像。

arryTableData = [[NSArray alloc] initWithObjects:[NSString stringWithFormat:@"%@", locName], 
          [NSString stringWithFormat:@"%@", locPhone], 
          @"Address Info", 
          @"Access Icons", 
          nil]; 

所以就在locName之前,我想讓locImage在那裏。如何將圖像加載到數組中,然後將其顯示在單元格中?

感謝

湯姆

回答

5

我會建議不要一個UIImage加載到NSArray的。 只需將「ImageName」(文件名)作爲NSString添加到NSArray中即可。

當你需要證明你的形象,做到這一點:

UIImage * image = [UIImage imageNamed:[arryTableImage objectAtIndex:indexPath.row]]; 
cell.imageView.image = image; 

您需要的NSString加載到NSArray的arryTableImage。

好吧四個你?

+1

+1如果可能,我更喜歡存儲圖像位置以避免記憶打擊,直到我需要圖像。注意:使用UIImage的'imageNamed:'方法將緩存圖像。這取決於情況。如果您只有一個大圖片,請使用'imageWithContentsOfFile:'來避免緩存。 – Sam

+0

非常感謝。我如何設置它只出現在第一行,只顯示圖像,沒有別的(基本上它是位置的標誌,我想顯示它很大) – TMB87