2012-07-12 19 views
0

我使用單個視圖中創建一個應用程序based.Now我必須顯示15號有關每個menu.So菜單和描述的我想用UITableView在that.While選擇插入的細胞應該顯示長文本&圖像content.Do我要創建每個ViewController每個類別或任何快捷方式添加描述編程 這裏是我的表視圖代碼如何創建的UITableView和細節視圖分別

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

// Set up the cell... 
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:15]; 
cell.textLabel.text = [NSString stringWithFormat:@"Cell Row #%d", [indexPath row]]; 

return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
// open a alert with an OK and cancel button 
NSString *alertString = [NSString stringWithFormat:@"Clicked on row #%d", [indexPath row]]; 
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:alertString message:@"" delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil]; 
[alert show]; 
[alert release]; 
} 

這是創建UIAlertView當細胞感動。

我怎樣才能長文本和圖像display.Any想法請做。

+0

這將取決於你想顯示那些15個視圖控制器以及所涉及的複雜的內容。 – rishi 2012-07-12 06:58:17

+0

關於詳細視圖,你可以得到點擊索引,他們可以顯示其詳細視圖! – NSException 2012-07-12 07:24:32

回答

2

我認爲你可以使用導航控制器和它推的tableView。在選擇表單元格時,您應該推送一個detailView(所有單元格的一個詳細視圖)。這僅適用於在detailView中必須顯示相同格式的詳細信息數據的情況。否則,如果你不得不爲每個選擇不同的屏幕,那麼你可以設計所有這些屏幕,這也會使它變得沉重。

+0

感謝您的回答,這是單細胞的描述..但我需要15種細胞在tableview中的15種描述..我該如何實現這一目標? – Dany 2012-07-12 08:51:52

+0

如果所有的小區描述的UI設計是一樣的,你只需要更改描述字段的字段的內容,那麼你就可以根據所選擇的row.index改變的內容。如果所有的描述都有不同的UI,那麼你需要爲所有的設計不同的設計。 – Zaraki 2012-07-12 09:07:25

2

您可以創建一個視圖控制器至極用圖片和文字,視圖控制器裏面你應該創建的UITextView和初始化的UIImageView。視圖控制器必須是這樣的:

@interface ViewController : UIViewController { 
    UIImageView *imageView; 
    UITextView *textView; 
} 

-(id)initWithText:(NSString *)text image:(UIImage *)image; 

@end 

@implementation ViewController 

-(id)initWithText:(NSString *)text image:(UIImage *)image { 
    if (self = [super init]) { 
     //ImageView initialization 
     imageView.image = image; 
     //TextViewInitialization 
     textView.text = text; 
    } 
    return self; 
} 

@end 

在視圖控制器,其中表視圖,您可以創建2個陣列具有相應的圖片和文字的細胞。 然後didSelectRowAtIndexPath方法:一定是這樣的:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    ViewController *vc = [[ViewController alloc]initWithText:[textArray objectAtIndex:indexPath.row] image:[imagesArray objectAtIndex:indexPath.row]]; 
    [[self navigationController] pushViewController:vc animated:YES]; 
    [vc release]; 
} 
+0

感謝您的回答,這是單細胞的描述..但我需要15種細胞在tableview中的15種描述..我怎麼能做到這一點? – Dany 2012-07-12 08:38:10

+0

您需要用15個不同的字符串填充textArray。數組中的字符串索引必須對應於單元格... – Moonkid 2012-07-12 10:57:21

相關問題