2013-04-30 38 views
5

Tôi đang cố gắng thêm nsindexpath vào một mảng .. tôi có thể thêm chỉ một đường dẫn chỉ mục .if tôi cố gắng thêm một đường dẫn chỉ mục khác vào mảng .. trình gỡ lỗi chỉ hiển thị đường dẫn chỉ mục mới nhất.Cách thêm nhiều NSIndexPath vào NSMutableArray

for (int i = 0 ; i<[notificationArray count]; i++) 
     { 
      selectedSymptIndexPath = [NSIndexPath indexPathForRow:selectedSymptomIndex inSection:keyIndexNumber]; 
      selectedSympIPArray = [[NSMutableArray alloc]init]; 
      [selectedSympIPArray addObject:selectedSymptIndexPath]; 
     } 

ngay cả khi tôi cố gắng để đưa [selectedSympIPArray addObject:selectedSymptIndexPath]; bên ngoài vòng lặp for vẫn chỉ thêm các indexPath mới nhất của nó chứ không phải là hiển thị nhiều indexpaths

Trả lời

8

Trong code của bạn, bạn alloc mỗi khi trong lần lặp. Nó hoàn toàn sai. Tìm lỗi của bạn.

Bạn có thể sử dụng mã này ....

selectedSympIPArray = [NSMutableArray array]; 
for (int i = 0 ; i<[notificationArray count]; i++) 
     { 
      selectedSymptIndexPath = [NSIndexPath indexPathForRow:selectedSymptomIndex inSection:keyIndexNumber];    
      [selectedSympIPArray addObject:selectedSymptIndexPath]; 
     } 
12

Bạn đang alloc init'ing mảng mỗi khi trong vòng lặp, không làm điều đó .

Hãy thử điều này:

selectedSympIPArray = [[NSMutableArray alloc]init]; 

for (int i = 0 ; i<[notificationArray count]; i++) 
{ 
    selectedSymptIndexPath = [NSIndexPath indexPathForRow:selectedSymptomIndex inSection:keyIndexNumber]; 
    [selectedSympIPArray addObject:selectedSymptIndexPath]; 
} 
+0

@raptor là nó làm việc cho bạn? – satheeshwaran

+0

..nó hoạt động – raptor

+0

nhưng khi tôi cuộn uitableview sau một thời gian, nó sẽ bị chậm lại – raptor

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