How to replace the NSMutableArray section object in UITableview? - ios

Below is my NSMutableArray response
(
(
0,
1,
1,
0,
0,
0
),
(
0,
0,
0
)
)
This is my code,here i need to replace the object
[CoutReplace[indexPath.section] replaceObjectAtIndex:indexPath.row withObject:#"1"];
when i am using this code it is crashing.
Bellow is my crash report.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance 0x600000e6fe40'
Here "CoutReplace" is NSMutableArray.

Related

Loop through array then compare current object to string

I'm trying to iterate through an NSArray and check if an objectAtIndex is equal to a string.
NSLog(#"%#", myArray) // 3 items. 1 of them is "a"
for (id object in myArray)
{
NSLog(#"What"); // 3 times
if ([object isEqual:#"a"]) {
NSLog(#"Hello"); // Never gets executed
}
}
The problem is, the NSLog in the if statement never gets executed?
Edit
(
(
a
),
(
01
),
(
a
),
(
03
)
)
When I set it to isEqualToString, I get this error:
2015-03-30 14:42:54.206 MyApp[1575:50954] -[__NSArrayM isEqualToString:]: unrecognized selector sent to instance 0x7fe721ce3bf0
2015-03-30 14:42:54.215 MyApp[1575:50954] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM isEqualToString:]: unrecognized selector sent to instance 0x7fe721ce3bf0'
Your problem is that you have an array that contains three sub-arrays, each of which contain, what is presumably, a single string. You can tell this because of the extra ()'s around the strings in the log output, and by the fact that it's telling you that you tried to send a selector to __NSArrayM.
Here is a quick fix:
NSLog(#"%#", myArray) // 3 items. 1 of them is "a"
for (NSArray *array in myArray)
{
NSLog(#"What"); // 3 times
if ([array.firstObject isEqualToString:#"a"])
{
NSLog(#"Hello"); // Never gets executed
}
}
But as others have pointed out you probably want to use isEqualToString: since it will be more performant.
You may also want to reconsider the code that is generating this nested array structure, or the schema that you're using in general, because it seems... unnecessary. Without further information there's not much to be done.

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSCFConstantString stringByAppendingString:]: nil argument'

Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '*** -[__NSCFConstantString
stringByAppendingString:]: nil argument'
iam getting this error help me out..
- (IBAction)sendAction:(id)sender
{
if([_chatTextField.text length] > 0)
{
NSString* po = getUser.ofUser;
bubbleTable.typingBubble = NSBubbleTypingTypeNobody;
NSBubbleData *messageBubble = [NSBubbleData dataWithText:_chatTextField.text date:[NSDate dateWithTimeIntervalSinceNow:0] type:BubbleTypeMine];
[bubbleData addObject:messageBubble];
[bubbleTable reloadData];
[bubbleTable scrollBubbleViewToBottomAnimated:YES];
NSLog(#"getuserAccount:%#", getUser.account);
NSLog(#"TextField:%#", _chatTextField.text);
NSLog(#"Po:%#", po);
NSLog(#"UserID:%#", [NSString stringWithFormat:#"%ld", (long)getUser.Id]);
NSLog(#"chatMessageKey:%#", chatMessageKey);
[[QuoteMessageController SharedInstance] SendChatMessageTo:getUser.account withContent:_chatTextField.text toUserId:[NSString stringWithFormat:#"%ld", (long)getUser.Id] andOFId:po andVerifyKey:chatMessageKey];
}
//[self StopInteraction];
}
outPut Iam getting is..
> userAccount:(null)
> 2015-01-12 19:09:26.050 SourceSage[6842:737878] TextField:haii
> 2015-01-12 19:09:26.051 SourceSage[6842:737878] Po:(null)
> 2015-01-12 19:09:26.052 SourceSage[6842:737878] UserID:0
> 2015-01-12 19:09:26.052 SourceSage[6842:737878] chatMessageKey:2365891
> 2015-01-12 19:09:44.240 SourceSage[6842:737878] dbPath:/var/mobile/Containers/Data/Application/C06E4910-88B7-46BF-A7A9-8FBDCDA44B67/Documents/Recipes/SourceSageDB.db
> 2015-01-12 19:09:44.264 SourceSage[6842:737878] dbPath:/var/mobile/Containers/Data/Application/C06E4910-88B7-46BF-A7A9-8FBDCDA44B67/Documents/Recipes/SourceSageDB.db
> 2015-01-12 19:09:44.273 SourceSage[6842:737878] *** Terminating app due to uncaught exception
> 'NSInvalidArgumentException', reason: '*** -[__NSCFConstantString
> stringByAppendingString:]: nil argument'
> *** First throw call stack:
> (0x2ce265f7 0x3a560c77 0x2ce2653d 0x2da749b3 0x1224b9 0xd2465 0x85569 0x302ff197 0x302ff139 0x302e9d1d 0x302feb69 0x302fe843
> 0x302f8151 0x302ce8c5 0x30542373 0x302cd307 0x2cdecfd7 0x2cdec3eb
> 0x2cdeaa69 0x2cd37b31 0x2cd37943 0x340f0051 0x3032d6f1 0x118fd9
> 0x3aafcaaf)
> libc++abi.dylib: terminating with uncaught exception of type NSException
> (lldb)
The log exactly says NSString* po = getUser.ofUser; returns null or nil value.
You're passing this nil argument to the method [[QuoteMessageController SharedInstance] SendChatMessageTo: withContent: toUserId: andOFId:po andVerifyKey:];.

iOS issue with loop in NSDictionary

I have array like this:
(
{
code = "+39";
country = "Italy (+39)";
},
{
code = "+93";
country = "Afghanistan(+93)";
},
)
And i trying to get elements on loop like this discribed here
So there are my code:
int i = 0;
for (id key in self.codes) {
NSDictionary *value = [self.codes objectForKey:key];
if(row == i)
{
return [value objectForKey:#"country"];
}
i++;
}
and i have this error:
2014-10-22 15:49:56.791 Surfree[1097:60b] -[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x15387e00
2014-10-22 15:49:56.793 Surfree[1097:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x15387e00'
*** First throw call stack:
(0x2e385ecb 0x38b20ce7 0x2e3897f7 0x2e3880f7 0x2e2d7058 0xe51af 0x30e27bf9 0x30e2ae81 0x3112984b 0x30cea179 0x30c913db 0x30cd5c8f 0x3107ec81 0x31128d7b 0x30e29bcf 0x30e29a85 0x30e2a7eb 0x30e27159 0x30e2724f 0x30bb6d17 0x30bb6a85 0x30bb63ed 0x2ececd33 0x30bb6271 0x30bc2ffd 0x30bc2a73 0x30d8c165 0x30bb6d17 0x30bb6a85 0x30bb63ed 0x2ececd33 0x30bb6271 0x30bc2ffd 0x30bc2a73 0x30d8b979 0x30bc90b5 0x30d8b1cd 0x30d483b1 0x30c6546f 0x30c65279 0x30c65211 0x30bb72e5 0x3083331b 0x3082eb3f 0x3082e9d1 0x3082e3e5 0x3082e1f7 0x30bba99f 0x2e350faf 0x2e350477 0x2e34ec67 0x2e2b9729 0x2e2b950b 0x332286d3 0x30c1a871 0xe6bd9 0x3901eab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
How i can to fix it? and Why i have error?
Whe i do debug i see that error in this line :
NSDictionary *value = [self.codes objectForKey:key];
It looks like self.codes is an array; you can't access that like a dictionary. The correct way to use your code is like this:
int i = 0;
for (NSDictionary *value in self.codes) {
if(row == i)
{
return [value objectForKey:#"country"];
}
i++;
}
However, it really just looks like you're trying to access this:
self.codes[row][#"country"]
The error is that you call a NSDictionary method on the NSArray method.
self.codes is a NSArray, it needs to be a NSDictionary.

Xcode call stack

I'm getting an exception while running iOS app in simulator
2013-09-16 18:03:44.346 DEV[26529:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSDecimalNumber isEqualToString:]: unrecognized selector sent to instance 0xf98fc70'
*** First throw call stack:
(0x17bf012 0x1c38e7e 0x184a4bd 0x17aebbc 0x17ae94e 0x1b813 0x1c4c705 0x653920 0x6538b8 0x714671 0x714bcf 0x713d38 0x917213 0x1787afe 0x1787a3d 0x17657c2 0x1764f44 0x1764e1b 0x29db7e3 0x29db668 0x65065c 0x25c9 0x2505 0x1)
UPD:
Exception is caused by the following code:
if([self.media.idtype isEqualToString:IMAGETYPE])
Where idtype is #property(retain, nonatomic) NSString *idtype; and IMAGETYPE is static NSString *VIDEOTYPE = #"2";
How can I see function names instead of addresses?
isEqualToString can compare two NSstrings not the other type of data that u are comparing which is NSDecimalNumber
convert your NSDecimalNumber to nsstring then do this
NSDecimalNumber* dec1;
NSString* str;
str = dec1.stringValue;
NSString *str2=#"world";
[str isEqualToString:str2];
There is some where in your code you are setting the value of property idtype (self.media.idtype). This must be the source of the problem:
Possible Problems could be Extracting contents from Webservice and while parsing you might be assigning it to the self.media.idtype object.

ObjC searching for # in a string (iOS # escape code)

I'm searching an NSString with an email to find the # character. Here's the code:
NSRange range = [string rangeOfString:#"#"];
if (range.location != NSNotFound) // do stuff
Here's the error I'm getting...
-[__NSCFNumber rangeOfString:]: unrecognized selector sent to instance 0x1e51c550
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber rangeOfString:]: unrecognized selector sent to instance 0x1e51c550'
Your string variable points to an instance of NSNumber, not an instance of NSString. You are initializing it incorrectly.

Resources