Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios NSMutableArray/UITableView_Ios_Objective C_Arrays_Uitableview - Fatal编程技术网

Ios NSMutableArray/UITableView

Ios NSMutableArray/UITableView,ios,objective-c,arrays,uitableview,Ios,Objective C,Arrays,Uitableview,我正在尝试使用以下选项创建UITableView(分组): Section 1: TextField for name of something Label + stepper for increasing the Sections where ppl can add options (Subclassed UITableViewCell) Section 2: (Default is this section, that they already can add things) First

我正在尝试使用以下选项创建UITableView(分组):

Section 1:
TextField for name of something
Label + stepper for increasing the Sections where ppl can add options (Subclassed UITableViewCell)

Section 2: (Default is this section, that they already can add things)
First cell of section is an cell (Add Option). People click this to get an extra cell in section 2 where they can get things going. When they click this, an UIAlertView will show up with a textfield.

Section 3:
Same as section 2 from now on. 
所以我已经有了这个设置,但现在我正在尝试将“添加选项”添加到带有数组的部分。因为add选项始终是节的最后一个索引路径。因此将标识符链接到它。然后,当我初始化应用程序时,默认数组如下所示:

__diceArray = [NSMutableArray arrayWithObjects:[NSArray arrayWithObject:@"THIS IS FOR SECTION ONE"], [NSArray arrayWithObjects:@"Option in section 2", @"Option for section 2", nil], nil];
但现在我在尝试向第2节添加内容时遇到了一些问题,比如我无法从第2节将数组添加到我的数组中。当我尝试重新加载tableview时,它崩溃了

有人有更好的方法吗

编辑:

忘记了一些事情,就在这里:

我正在像这样更新数组

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 1) {
        NSString *name = [alertView textFieldAtIndex:0].text;
        [[self _diceArray] insertObject:name atIndex:2];
        NSLog(@"%@", self._diceArray);

        [[self _tabel]reloadData];
    }
}
插入对象,但不在节的数组中: ( ( “”//这是第一节中的用户配置 ), ( 测试,//需要在这里。 Test//最后一个用于add选项prototype单元格。 ), adsf//这是添加的对象。 )

此外,重新加载数据也会崩溃:

*** First throw call stack:
(
    0   CoreFoundation                      0x0000000101bb1495 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001016b199e objc_exception_throw + 43
    2   CoreFoundation                      0x0000000101c4265d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x0000000101ba2d8d ___forwarding___ + 973
    4   CoreFoundation                      0x0000000101ba2938 _CF_forwarding_prep_0 + 120
    5   multiDice                           0x0000000100003752 -[AddViewController tableView:numberOfRowsInSection:] + 146
    6   UIKit                               0x0000000100471e1e -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 2245
    7   UIKit                               0x00000001004751c2 -[UITableViewRowData numberOfRows] + 97
    8   UIKit                               0x000000010032323c -[UITableView noteNumberOfRowsChanged] + 114
    9   UIKit                               0x0000000100322d27 -[UITableView reloadData] + 717
    10  multiDice                           0x00000001000042dc -[AddViewController alertView:clickedButtonAtIndex:] + 332
    11  UIKit                               0x0000000100785ec8 -[_UIModalItemsCoordinator _notifyDelegateModalItem:tappedButtonAtIndex:] + 151
    12  UIKit                               0x000000010034c53e -[_UIModalItemAlertContentView tableView:didSelectRowAtIndexPath:] + 364
    13  UIKit                               0x00000001003265c2 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1312
    14  UIKit                               0x00000001003266eb -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 221
    15  UIKit                               0x0000000100277100 _applyBlockToCFArrayCopiedToStack + 316
    16  UIKit                               0x0000000100276f71 _afterCACommitHandler + 460
    17  CoreFoundation                      0x0000000101b7cdc7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    18  CoreFoundation                      0x0000000101b7cd37 __CFRunLoopDoObservers + 391
    19  CoreFoundation                      0x0000000101b5c522 __CFRunLoopRun + 946
    20  CoreFoundation                      0x0000000101b5bd83 CFRunLoopRunSpecific + 467
    21  GraphicsServices                    0x0000000103d28f04 GSEventRunModal + 161
    22  UIKit                               0x000000010025ee33 UIApplicationMain + 1010
    23  multiDice                           0x0000000100002c73 main + 115
    24  libdyld.dylib                       0x00000001022495fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

亲切的问候

更新:

用2个数组初始化数组

__diceArray = [NSMutableArray arrayWithObjects:[NSArray arrayWithObject:@"THIS IS FOR SECTION ONE"], 
此代码将在初始化NSMutableArray时使用的2个数组之后,向NSMutableArray中添加一个字符串

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 1) {
        NSString *name = [alertView textFieldAtIndex:0].text;
        [[self _diceArray] insertObject:name atIndex:2];
因此,当它请求numberOfRowsInSection时,当它到达第三个条目时,它是一个NSString,显然不响应count

我不确定您试图通过从alertview添加来实现什么,您是要添加到现有部分还是新部分?无论哪种方式,您都需要记住要将其添加到的节,在该节中获取NSMutableArray并插入对象。但是,正如我在开始时所说,您需要更改_diceArray的初始值

如果我们要帮助您,您需要帮助我们,例如,您会遇到什么错误,但是作为初学者,如果您试图为每个部分向数组添加元素,那么它们也需要是
NSMutableArray

__Array = [NSMutableArray arrayWithObjects:[NSMutableArray arrayWithObject:@"THIS IS FOR SECTION ONE"], [NSMutableArray arrayWithObjects:@"Option in section 2", @"Option for section 2", nil], nil];

但是,正如我所说,您需要告诉我们错误,当您在
XLDataSet
中插入/删除项节时,查看您如何尝试更新uu Array

自动更新UITableView也可能很有用

尝试创建NSMutableArray的NSMutableArray(不是NSArray-immutable array)在堆栈崩溃时能否共享堆栈跟踪?对我的帖子进行了编辑。抱歉提供了太多信息。不确定您的更新是否有帮助,
[self\u diceArray]
与\u Array有什么关系?您已经给了我们堆栈转储,但是应该会有一条错误消息,告诉您什么对象没有响应选择器
-[NSObject(NSObject)没有识别选择器:+205
?\u diceArray是
NSMutableArray
嗯,好了,您有一点没有考虑它,我想在他们单击添加选项的退出部分添加一个选项。需要找到一种方法来了解UIAlertView添加的部分。也在重新思考我的阵列。。因为最后一个索引路径不会总是空的,对于我的addOption原型单元格。。我们需要重新考虑这一点