我有一個程序從Core Data
中獲取,然後在程序中獲取某些東西時,它會在我的UITableView
中顯示結果。現在如何實例化CD實體而不被提取
我的問題是,有時我需要用戶到另一個UITableCell
添加到我UITableView
但我tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
計數的元素在我的數組持有我的ExerciseData
實體。
我試圖創建一個ExerciseData
實體,就好像它是一個對象,但這不起作用並使程序崩潰。 做
if ([[_ed objectAtIndex:indexPath.row] weight]) {
NSLog(@"%@",_ed);
cell.weightInput.text = [NSString stringWithFormat:@"%@",[[_ed objectAtIndex:indexPath.row] weight]];
}
它拋出了讓我明白,我不能啓動這樣的一個CD實體錯誤CoreData: error: Failed to call designated initializer on NSManagedObject class 'ExerciseData'
。
然後我試圖添加到NSArray _ed
一個NSString
,然後檢查類,如果class type
是一類NSString
它不應該嘗試設置cell.weightInput.text
我的問題是2:1 )是有一種方法來啓動一個實體,以便我可以將它插入到數組中,然後檢查是否爲空,以便我可以在稍後的if statement
上驗證它?
如果這是不可能的 2)我怎麼能填充NSArray
的東西,然後可以驗證&升級到multimple項目,但也時有ExerciseData
工作?
我的目標是,此人使用- addSet
創造多次按下按鈕,然後我需要驗證無論是內部的一個新UITableCell
這樣,如果是ExerciseData entity
和性質權重設置爲填充cell.weightInput.text
或以其他方式不填充它
- (void) addNewSet {
ExerciseData * newEd = [[ExerciseData alloc] init];
NSMutableArray* ar = [[NSMutableArray alloc]initWithArray:_ed];
[ar addObject:newEd];
_ed = [[NSArray alloc] initWithArray:ar];
[_mytable reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
workoutCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
cell = [[workoutCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
}
cell.weightInput.text = @"";
if (indexPath.row < [_ed count]) {
if (![[[_ed objectAtIndex:indexPath.row] class] isKindOfClass:[NSString class]]) {
NSLog(@"%@",_ed);
cell.weightInput.text = [NSString stringWithFormat:@"%@",[[_ed objectAtIndex:indexPath.row] weight]];
}
}
//...
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([_ed count] == 0) {
return 1;
} else {
return [_ed count];
}
}