NSDictionary를 사용하여 사용자 정의 UItableView 데이터 행 채우기

1743 단어 UITableView
.h 파일
@interface DetailsViewController : UITableViewController {    

    NSDictionary *dict;

}



@property (nonatomic, retain) NSDictionary *dict;


 
.m 파일 코드
@implementation DetailsViewController

@synthesize dict;


  
- (void)viewDidLoad

{

	self.dict = [NSDictionary dictionaryWithObjectsAndKeys:

				 @"Alfred", @"Name", 

				 @"Chief Executive Officer", @"Title", 

				 nil];	//[mydict release];



	[super viewDidLoad];

}


 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return [[dict allKeys] count];

}


  
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CellIdentifier = @"Cell";

    

    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];

		cell = [nib objectAtIndex:0];

    }

		

	NSArray * sortedKeys = [[dict allKeys] sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)];

    NSString * key = [sortedKeys objectAtIndex: indexPath.row];

    NSString * value = [dict objectForKey: key];



	cell.name.text = key;

	cell.value.text = value; 

    

	//   

	UIView *lineView = [[[UIView alloc] initWithFrame:CGRectMake(80, 0, 1, cell.contentView.bounds.size.height)] autorelease];

	lineView.backgroundColor = [UIColor grayColor];

	[cell.contentView addSubview:lineView];

	

    return cell;

}


 

좋은 웹페이지 즐겨찾기