2010-12-29 47 views
7

Tôi đang cố gắng kích hoạt chế độ chỉnh sửa cho UITableView. Khi tôi nhấp vào nút "Chỉnh sửa", nó thay đổi thành "Xong" nhưng các dấu trừ màu đỏ trừ tròn không hiển thị trong bảng. Tôi đang đăng bài dưới đây một số phương pháp của lớp. Ứng dụng đại biểu đã tạo Tab Tab và các chế độ xem bên trong các tab có trình điều khiển điều hướng. tất cả được thực hiện trong mã, ít được thực hiện với các tập tin nib. Chuyện gì vậy?Chế độ chỉnh sửa UITableView không hoạt động

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [ikub.subscriptions count]; 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    int i = [indexPath row]; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"]; 
    } 
    Subscriptions *s = [ikub.subscriptions objectAtIndex:i]; 
    cell.textLabel.text   = [s title]; 
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ artikuj te rinj, %@ artikujt te lexuar", [s new], [s read]]; 
    if (deleteActive) { 
     cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 
    } else { 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 
    return cell; 
} 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    Subscriptions *s = [ikub.subscriptions objectAtIndex:[indexPath row]]; 
     NSString *address = [[NSString alloc] init]; 
     NSString *type = [NSString stringWithString:[s type]]; 
     if ([type isEqualToString:@"Category"]) { 
      address = [NSString stringWithFormat:@"http://www.ikub.al/Rss.aspx?node=9e26cdb8-dba6-4504-8bb6-29f0753be179~%@", [s code]]; 
     } else if ([type isEqualToString:@"Tag"]) { 
      address = [NSString stringWithFormat:@"http://www.ikub.al/Rss.aspx?tag=%@", [s code]]; 
     } 
     address = [address stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; 
     SubscriptionStories *ss = [[SubscriptionStories alloc] init]; 
     ss.address = address; 
     ss.title = [s title]; 
     [self.navigationController pushViewController:ss animated:YES]; 
     [ss release]; 
} 
- (void)viewWillAppear:(BOOL)animated { 
    [subscriptionsTable reloadData]; 
} 
- (void)viewDidLoad { 
    refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:nil]; 
    self.navigationItem.leftBarButtonItem = refreshButton; 
    [refreshButton release]; 
    self.navigationItem.rightBarButtonItem = self.editButtonItem; 
    [super viewDidLoad];  
} 
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {  
    return YES; 
} 
+0

hey olsi xin vui lòng chỉnh sửa câu hỏi của bạn, bằng cách định dạng đúng. Rất khó để hiểu mã. Không có khoảng cách giữa kết thúc và bắt đầu của các phương thức. – iPhoneDev

Trả lời

3

Bạn không kế thừa chính xác.

Bạn sẽ không nhận được bất kỳ thứ gì ngoài UIViewController, nó chỉ chứa các chế độ xem. Tôi đề nghị bạn thử UITableViewController.

+1

Không có gì để làm với thừa kế nếu ông có một đối tượng tableView và UIViewController là đại biểu của nó. –

1

Đã sửa lỗi! Đã phải kế thừa từ UITableViewController không UIViewController.

2

đâu bạn viết phương pháp khác của phương pháp xem chỉnh sửa uitable Như thế này

-(void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

} 

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { 

    return UITableViewCellEditingStyleDelete; 
} 

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // If row is deleted, remove it from the list. 
    if (editingStyle == UITableViewCellEditingStyleDelete) 
    { 
     rowNumber = indexPath.row; 
     UIActionSheet *registerActionSheet = [[UIActionSheet alloc] initWithTitle:@"Sure You Want To Delete?"delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Yes", nil]; 
     registerActionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque; 
     [registerActionSheet showInView:self.view]; 
     [registerActionSheet release]; 
     // delete your data item here 
     // Animate the deletion from the table. 
     //[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    } 
} 
17

Việc thừa kế không có bất kỳ tác động vào nó.

Bạn có thể sử dụng phương pháp này nó hoạt động khi bạn gán nút bên phải của navigationController cho nó.

- (void)setEditing:(BOOL)editing animated:(BOOL)animated { 
    [super setEditing:editing animated:animated]; 
    [tableView setEditing:editing animated:YES]; 
} 

Hoặc bạn có thể viết một phương pháp mà cơ bản Toggles bang UITableView như

[tableView setEditing:TRUE]; 

và khi nút đã trở nên thực hiện sau đó chuyển đổi nó để

[tableView setEditing:FALSE]; 
+1

tôi đồng ý, bỏ phiếu cho ở trên, tôi sử dụng UIViewController bình thường và nó hoạt động tốt - thay vào đó bạn cần phải: 1. làm cho bộ điều khiển của bạn một đại biểu của UITableViewDelegate, UITableViewDataSource, 2. thực hiện - (void) setEditing: (BOOL) chỉnh sửa hoạt hình: (BOOL) hoạt hình, 3. lập trình thêm nút EDIT - self.navigationItem.rightBarButtonItem = self.editButtonItem – Anonymous

+0

UITableViewController là quá giới hạn đôi khi đó là lý do tại sao chúng tôi sử dụng UIViewController. Tốt đăng bài! Cảm ơn. –

Các vấn đề liên quan