利用程式設定
#pragma mark - Table view delegate
- (CGFloat) tableView: (UITableView *)aTableView heightForRowAtIndexPath: (NSIndexPath *)indexPath
{
return 70.0f;
}
如果想整個表格內縮 改變Style為Grouped
客制不同的Cell為不同的圖片 .h
@interface Dialogue : UITableViewController
{
NSArray *choice;
}
@property (nonatomic, retain) NSArray *choice;
- (void) initChoices;
@end
.m Table View Cell的Identifier CellIdentifier 記得加
@synthesize choice;
- (void)viewDidLoad
{
[super viewDidLoad];
[self initChoices];
}
//title僅檢查用 實際作用是image
- (void) initChoices
{
NSDictionary *allChoice = [[NSDictionary alloc] initWithObjectsAndKeys:
@"content1", @"title",
@"content1.png", @"image", nil];
NSDictionary *myChoice = [[NSDictionary alloc] initWithObjectsAndKeys:
@"content2", @"title",
@"content2.png", @"image", nil];
choice = [[NSArray alloc] initWithObjects: allChoice, myChoice, nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [choice count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSDictionary *each = [self.choice objectAtIndex: indexPath.row];
//cell.textLabel.text = [each objectForKey: @"title"];
UIImage *image = [UIImage imageNamed: [each objectForKey: @"image"]];
UIImageView *imageView = [[UIImageView alloc] initWithImage: image];
cell.backgroundView = imageView;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//把預設表格格線消除
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
return cell;
}


沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。