2013-05-12 58 views
-1

我怎樣才能在表我如何能在表中添加圖像爲每個按鈕

我有表中8個按鈕添加一個圖像的每一個按鈕,我希望把不同的圖像爲每個按鈕

我有這樣的代碼可以如何修改以接受8個圖像

- (UIImage *)cellBackgroundForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
NSInteger rowCount = [self tableView:[self tableView] numberOfRowsInSection:0]; 
NSInteger rowIndex = indexPath.row; 
UIImage *background = nil; 

if (rowIndex == 0) { 
    background = [UIImage imageNamed:@"Button01.png"]; 
} else if (rowIndex == rowCount - 1) { 
    background = [UIImage imageNamed:@"Button02.png"]; 
} else { 
    background = [UIImage imageNamed:@"Button03.png"]; 
} 

return background; 
} 

回答

0

形成陣列包含圖片的所有名字。

self.imagesArray = @[@"Button01.png",@"Button02.png",@"Button03.png",...]; 

,然後訪問它的tableView:cellForRowAtIndexPath:或裏面,你使用indexPath找到從imagesArray

- (UIImage *)cellBackgroundForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSArray *imagesArray = @[@"Button01.png",@"Button02.png",@"Button03.png"]; 

    return [UIImage imageNamed:imagesArray[indexPath.row]; 
} 
對應的圖像構成單元
相關問題