2013-08-20 2 views
0

테이블 뷰에 마지막 셀 행을 추가 할 때이 문제가 있습니다. 누군가 제 코드에 마지막 행이 표시 될 때 잘못된 점을 알려주실 수 있습니까?하지만 테이블을 아래로 스크롤하면 다른 곳에서도 나타납니다. 어떤 도움이라도 대단히 감사하겠습니다. 고마워요. 여기에 내 코드입니다 :마지막 뷰 셀 (sqlite 테이블에 포함되지 않음)을 tableView에 추가합니다.

@interface ViewOrderViewController : UIViewController < UITableViewDataSource, UITableViewDelegate> { 
    IBOutlet UITableView *tabView; 
} 


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [appDelegate.vieworderArray count] + 1; 
} 

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"]; 
    } 
NSUInteger row = [indexPath row]; 

if(row == [appDelegate.vieworderArray count]) { 
    cell.textLabel.text = [NSString stringWithFormat:@"extra cell"]; 
}else{    
    Vieworder *vieworderObj = (Vieworder *)[appDelegate.vieworderArray objectAtIndex:indexPath.row]; 

    NSMutableString *mcmenuNameQuantity = [NSMutableString stringWithFormat:@"%@ X %i", vieworderObj.mcmenu_name, vieworderObj.mcmenu_quantity]; 
    UILabel *mcmenuLabel = [[UILabel alloc] initWithFrame:CGRectMake(45, 0, 200, 25)]; 

    [mcmenuLabel setFont:[UIFont systemFontOfSize:13.0f]]; 
    [mcmenuLabel setText:mcmenuNameQuantity];  
    UILabel *mcmenuPricexquantity = [[UILabel alloc] initWithFrame:CGRectMake(213, 0, 60, 25)]; 
    [mcmenuPricexquantity setFont:[UIFont systemFontOfSize:12.0f]]; 
    mcmenuPricexquantity.textAlignment = NSTextAlignmentRight; 
    NSMutableString *mcmenuPriceQuantityString = [NSMutableString stringWithFormat:@"%0.2f", vieworderObj.mcmenu_total_price]; 
    mcmenuPricexquantity.numberOfLines = 2; 
    [mcmenuPricexquantity setText:mcmenuPriceQuantityString]; 

    UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    deleteButton.frame = CGRectMake(12.0f, 0.0f, 25.0f, 25.0f); 
    deleteButton.tag = indexPath.row; 
    UIImage* imageDelete = [[UIImage alloc] init]; 
    imageDelete = [UIImage imageNamed:[NSString stringWithFormat:@"vieworder_delete.png"]]; 
    [deleteButton setImage:imageDelete forState:UIControlStateNormal] 
    [deleteButton addTarget:self action:@selector(performExpand:) forControlEvents:UIControlEventTouchUpInside]; 

    UIButton *editButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    editButton.frame = CGRectMake(280.0f, 0.0f, 25.0f, 25.0f); 
    UIImage* imageEdit = [[UIImage alloc] init]; 
    imageEdit = [UIImage imageNamed:[NSString stringWithFormat:@"vieworder_edit.png"]]; 
    [editButton setImage:imageEdit forState:UIControlStateNormal]; 
    editButton.tag = indexPath.row; 
    [editButton addTarget:self action:@selector(buttonClicked2:) forControlEvents:UIControlEventTouchUpInside]; 

    [cell.contentView addSubview:deleteButton ]; 
    [cell.contentView addSubview:mcmenuLabel]; 
    [cell.contentView addSubview:mcmenuPricexquantity ]; 
    [cell.contentView addSubview:editButton ]; 
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 
}  
return cell; 

} 첫번째

답변

0

를 사용하여 간단한 코드

[email protected][@"A",@"B",@"C",@"D",@"E",@"F",@"A",@"B",@"C",@"D",@"E",@"F",@"A",@"B",@"C",@"D",@"E",@"F",@"A",@"B",@"C",@"D",@"E",@"F",@"A",@"B",@"C",@"D",@"E",@"F",@"A",@"B",@"C",@"D",@"E",@"F"]; 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [arr count]+1; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"]; 

    if (cell==nil) { 
     cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; 
    } 

    cell.textLabel.text=(indexPath.row==arr.count)[email protected]"End of Row":arr[indexPath.row]; 

    return cell; 
} 

그 다음 셀에 여러 하위 뷰를 추가하여 다른 조건을 몇 가지 문제가해야 다음 작동하는 경우 .ContentView.

관련 문제