2010-03-03 50 views

回答

5
  1. 新建文件(可可触摸类 - > UIViewController子类) 的UITableViewController子类,用XIB1的接口(同时检查)
  2. 打开XIB文件
  3. 改变视图样式(平纹>上属性检查员组)(苹果键+ 1)中的m文件
  4. 添加以下代码
 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 
 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return 2; 
} 
 
- (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]; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    } 

    if(indexPath.row == 0) { 
     cell.textLabel.text = @"Username"; 
     UITextField *field = [[[UITextField alloc] initWithFrame: CGRectMake(120, 10, 180, 30)] autorelease]; 
     [cell addSubview:field]; 

    } 
    else if(indexPath.row == 1) { 
     cell.textLabel.text = @"Password"; 
     UITextField *field = [[[UITextField alloc] initWithFrame: CGRectMake(120, 10, 180, 30)] autorelease]; 
     field.secureTextEntry = YES; 
     [cell addSubview:field]; 
    } 

    return cell; 
} 
 
- (NSString *)tableView: (UITableView *)tableView 
titleForHeaderInSection: (NSInteger)section 
{ 
    return @"Account"; 
} 
 
- (NSString *)tableView: (UITableView *)tableView 
titleForFooterInSection: (NSInteger)section 
{ 
    return @"If you don't have a twitter account, go to twitter.com to sign up."; 
} 
+0

惊人!谢谢! – 2010-03-04 16:19:56