سؤال

أحتاج إلى حذف الصف 1 من جدول في وظيفة حددتها. لكي تستخدم deleteRowAtIndexPath يجب عليك استخدام IndexPath مع قسم والصف محدد. كيف يمكنني إنشاء فهرس مثل هذا؟

صفيف مع int {1} كعضو له فقط سوف تحطم ؛ تنص رسالة NSLOG على أنه يجب تحديد القسم أيضًا.

*تحرير -> رمز يتعلق بحذف الخلية:

    NSIndexPath *myIP = [[NSIndexPath alloc] indexPathForRow:0 inSection:0];
    NSArray *myArray = [[NSArray alloc] initWithObjects:myIP, nil];
//  [self.tableView beginUpdates];
    [self.tableView deleteRowsAtIndexPaths:myArray withRowAnimation:UITableViewRowAnimationFade];
//  [self.tableView endUpdates];
هل كانت مفيدة؟

المحلول

يستخدم [NSIndexPath indexPathForRow:inSection:] لإنشاء مسار فهرس بسرعة.

تعديل: في سويفت 3:

let indexPath = IndexPath(row: rowIndex, section: sectionIndex)

نصائح أخرى

indexPathForRow هي طريقة الفصل!

يجب أن تقرأ الرمز:

NSIndexPath *myIP = [NSIndexPath indexPathForRow:0 inSection:0] ;

إجابة إلزامية في سويفت: NSIndexPath(forRow:row, inSection: section)

ستلاحظ ذلك NSIndexPath.indexPathForRow(row, inSection: section) غير متوفر في Swift ويجب عليك استخدام الطريقة الأولى لإنشاء IndexPath.

لسويفت 3 الآن: IndexPath(row: rowIndex, section: sectionIndex)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top