Mam do czynienia z problemem dotyczącym dodania wartości Null or nil
w NSArray
. Właściwie dodaję wartość Null
ponieważ moja tablica nie jest taka sama. Dodaję trzy tablice w Custom TableViewCell
dwie tablice są z usługi sieci web i jedna tablica jest z bazy danych. Oszczędzam IndexPath
w core data
, a następnie odzyskuję.Jak dodać wartość null 0r w "dynamicznym NSArray" w Objective C
Jak widać na obrazu mam oszczędności indexPath
STRING i przekształcenia go w NSInteger
z DidSelectAtIndexPath
i pokazać je w cellForRowAtIndexPath
. Mój problem polega na tym, że jest on zastępowany, ponieważ jest przechowywany w łańcuchu znaków. Tak, aby zapisać go w coredata
a i pobrać go, ale mam problem z niezaangażowania tablicy w cellforrowatindexpath
. Moje kodu jest jak ten
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *[email protected]"STI";
AuditTableViewCell *cell = (AuditTableViewCell *)[tableView dequeueReusableHeaderFooterViewWithIdentifier:STI];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AuditTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
cell.accessoryType=UITableViewCellAccessoryNone;
}
cell.audittitlelbl.text=[NSString stringWithFormat:@"%@",[idarray objectAtIndex:indexPath.row]];
cell.auditdesclbl.text=[NSString stringWithFormat:@"%@",[namearray objectAtIndex:indexPath.row]];
NSManagedObject *device2 = [devices objectAtIndex:indexPath.row];
NSMutableArray *Checkarray=[devices valueForKey:@"Key"]; // Hear in this array I am getting Index count problem
NSLog(@"Device =%@",device2);
NSLog(@"Check Array =%@",Checkarray);
if(indexPath.row == CurrentIndexPath)
{
cell.listlbl.text=GlobalString;
[cell setBackgroundColor:[UIColor greenColor]];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
CurrentIndexPath=indexPath.row;
NSLog(@"Current Index Path =%ld",(long)CurrentIndexPath);
GlobalIndexPath = [[NSString stringWithFormat: @"%ld", (long)CurrentIndexPath] mutableCopy];
NSManagedObjectContext *context = [self managedObjectContext];
if (self.device) {
// Update existing device
[device setValue:GlobalStringChk forKey:@"Key1"];
[device setValue:GlobalIndexPath forKey:@"Key"];
} else {
// Create a new device
NSManagedObject *newDevice = [NSEntityDescription insertNewObjectForEntityForName:@"Device" inManagedObjectContext:context];
[newDevice setValue:GlobalStringChk forKey:@"Key1"];
[newDevice setValue:GlobalIndexPath forKey:@"Key"];
}
NSError *error = nil;
// Save the object to persistent store
if (![context save:&error]) {
NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
}
[Audittable reloadData];
NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Device"];
self.devices = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];
}
To jest mój kod usłyszeć Jestem oszczędność indexpath
w coredata
i pobieranie go w tablicy. Mam problem z liczbą tablic w cellforrowatindexpath
. Jak mogę dodać wartość Null or nil
w tablicy, aby liczba była taka sama. Mój Array jest dynamicznym array.The Głównym problemem jest to, że muszę zmienić kolor komórki, jeśli użytkownik kliknie na it.when przechowywać wartość w NSInteger i przekształcić go w indexpath mogę zmienić kolor, ale tylko na jedną komórkę w time.Kiedy kliknę na inną wartość całkowitą komórki, pomiń. W związku z tym zapisuję go w podstawowych danych i odtwarzam, ale kiedy pobieram główną tablicę danych w cellforrowindexpath, następuje awaria z powodu innej liczby. Dzięki Advance!
Możliwy duplikat [jak dodać zero do nsmutablearray?] (Http://stackoverflow.com/questions/2057910/how-to-add-nil-to-nsmutablearray) – Puvanarajan
@Puvanarajan Zadaję pytanie Jak dodać dynamiczną tablicę, która jest pytaniem dla statycznej tablicy. I moje pytanie dotyczy problemu zliczania w cellforrowatindexpath. Przeczytaj pełne pytanie. – Muju
@Muju zostało rozwiązane? – Joshua