How to Create Contact QR code in iphone - iphone

I am working for Qr generator application and for that I have nice kyupay Library.
In that Library I need to pass string value and it returns QR Image.
It's working nice for text,Email and etc...
But Now i wants to create QR Image for Contact and Event And i don't know how to do this.
so My problem is what should be the logic for that ????
please suggest me or if you have code for that then please Share it.

Thanks for respond me on my question.
I finally creates a function that returns contact Qr code string.
It's easy but too long.
we have to check for data inputs from user and append sting as per data and create string.
I am Posting my code so it may help others and save theirs time.
-(NSString *)GenerateStringForContact{
NSString *str = #"";
NSMutableArray *arr1 =[[NSMutableArray alloc] init];
for (int i=0 ; i<[arrayAttributeName count]; i++) {
if ([[arrayAttributeName objectAtIndex:i] isEqualToString:#"First Name"]) {
if ([strContactType isEqualToString:#"ContactMecard"]) {
[arr1 addObject:#"N:"];
}else{
[arr1 addObject:#"FN:"];
}
}else if ([[arrayAttributeName objectAtIndex:i] isEqualToString:#"Last Name"]) {
// [arr1 addObject:#"N:"];
}else if ([[arrayAttributeName objectAtIndex:i] isEqualToString:#"Phone"]) {
[arr1 addObject:#"TEL:"];
}else if ([[arrayAttributeName objectAtIndex:i] isEqualToString:#"Email"]) {
[arr1 addObject:#"EMAIL:"];
}else if ([[arrayAttributeName objectAtIndex:i] isEqualToString:#"URL"]) {
[arr1 addObject:#"URL:"];
}else if ([[arrayAttributeName objectAtIndex:i] isEqualToString:#"Nickname"]) {
[arr1 addObject:#"NICKNAME:"];
}else if ([[arrayAttributeName objectAtIndex:i] isEqualToString:#"Title"]) {
[arr1 addObject:#"TITLE:"];
}else if ([[arrayAttributeName objectAtIndex:i] isEqualToString:#"Organization"]) {
[arr1 addObject:#"ORG:"];
}else if ([[arrayAttributeName objectAtIndex:i] isEqualToString:#"Birthday"]) {
[arr1 addObject:#"BDAY:"];
}else if ([[arrayAttributeName objectAtIndex:i] isEqualToString:#"Note"]) {
[arr1 addObject:#"NOTE:"];
}
}
NSMutableArray *contDetail = arrayAttributeValue;
if ([strContactType isEqualToString:#"ContactMecard"]) {
str = #"MECARD:";
// arr1 = [[NSArray alloc] initWithObjects:#"N:",#"TEL:",#"EMAIL:",#"URL:",#"NOTE:",#"NICKNAME:",#"BDAY:",#"ADR:",nil];
}else{
str = #"BEGIN:VCARD";
// arr1 = [[NSArray alloc] initWithObjects:#"N:",#"TEL:",#"EMAIL:",#"URL:",#"NOTE:",#"NICKNAME:",#"BDAY:",#"ADR:",#"TITLE:",#"ORG:",nil];
}
BOOL count = TRUE;
for (int i =0; i <[contDetail count]; i++) {
if (![[contDetail objectAtIndex:i] isEqualToString:#""]) {
NSString *tmp2 =#"";
if (i == 0 || i == 1) {
if (count) {
if ([strContactType isEqualToString:#"ContactMecard"]) {
tmp2 = [NSString stringWithFormat:#"%#,%#",[contDetail objectAtIndex:0],[contDetail objectAtIndex:1]];
NSString *tmp = [NSString stringWithFormat:#"%#%#",[arr1 objectAtIndex:i],tmp2];
str = [NSString stringWithFormat:#"%#;%#",str,tmp];
}else{
tmp2 = [NSString stringWithFormat:#"%# %#",[contDetail objectAtIndex:0],[contDetail objectAtIndex:1]];
NSString *tmp = [NSString stringWithFormat:#"%#%#",[arr1 objectAtIndex:i],tmp2];
str = [NSString stringWithFormat:#"%#\n%#",str,tmp];
}
count = FALSE;
}
}else{
tmp2 = [contDetail objectAtIndex:i];
NSString *tmp = [NSString stringWithFormat:#"%#%#",[arr1 objectAtIndex:i-1],tmp2];
if ([strContactType isEqualToString:#"ContactMecard"]) {
str = [NSString stringWithFormat:#"%#;%#",str,tmp];
}else{
str = [NSString stringWithFormat:#"%#\n%#",str,tmp];
}
}
}
}
if (![strContactType isEqualToString:#"ContactMecard"]) {
str = [NSString stringWithFormat:#"%#\nEND:VCARD",str];
}
NSLog(#"here string for generate code %#",str);
return str;
}
Thanks....

If you create a Contact QR code at this site: http://zxing.appspot.com/generator/ it provides for you the string it uses to create the QR Code. Maybe you can use this as inspiration?

Related

Retrieve contacts from iphone

I need to display all the list of contacts available in user's phone in UITableView.I can retrieve the contactName , PhoneNumber successfully.But when I add the data to NSMutableArray it adds some unusual characters.Could n;t understand wht the problem is
-(void)viewDidLoad
{
Names=[[NSMutableArray alloc]init];
ABAddressBookRef allPeople = ABAddressBookCreate();
CFArrayRef allContacts = ABAddressBookCopyArrayOfAllPeople(allPeople);
CFIndex numberOfContacts = ABAddressBookGetPersonCount(allPeople);
NSLog(#"numberOfContacts---%ld",numberOfContacts);
for(int i = 0; i < numberOfContacts; i++){
NSString* name = #"";
NSString* phone = #"";
NSString* email = #"";
ABRecordRef aPerson = CFArrayGetValueAtIndex(allContacts, i);
ABMultiValueRef fnameProperty = ABRecordCopyValue(aPerson, kABPersonFirstNameProperty);
ABMultiValueRef lnameProperty = ABRecordCopyValue(aPerson, kABPersonLastNameProperty);
ABMultiValueRef phoneProperty = ABRecordCopyValue(aPerson, kABPersonPhoneProperty);\
ABMultiValueRef emailProperty = ABRecordCopyValue(aPerson, kABPersonEmailProperty);
NSArray *emailArray = (__bridge NSArray *)ABMultiValueCopyArrayOfAllValues(emailProperty);
NSArray *phoneArray = (__bridge NSArray *)ABMultiValueCopyArrayOfAllValues(phoneProperty);
if (fnameProperty != nil) {
name = [NSString stringWithFormat:#"%#", fnameProperty];
}
if (lnameProperty != nil) {
name = [name stringByAppendingString:[NSString stringWithFormat:#" %#", lnameProperty]];
}
if ([phoneArray count] > 0) {
if ([phoneArray count] > 1) {
for (int i = 0; i < [phoneArray count]; i++) {
phone = [phone stringByAppendingString:[NSString stringWithFormat:#"%#\n", [phoneArray objectAtIndex:i]]];
}
}else {
phone = [NSString stringWithFormat:#"%#", [phoneArray objectAtIndex:0]];
}
}
if ([emailArray count] > 0) {
if ([emailArray count] > 1) {
for (int i = 0; i < [emailArray count]; i++) {
email = [email stringByAppendingString:[NSString stringWithFormat:#"%#\n", [emailArray objectAtIndex:i]]];
}
}else {
email = [NSString stringWithFormat:#"%#", [emailArray objectAtIndex:0]];
}
}
NSLog(#"NAME : %#",name);
NSLog(#"PHONE: %#",phone);
NSLog(#"EMAIL: %#",email);
NSLog(#"\n");
NSMutableDictionary *d=[[NSMutableDictionary alloc]init];
[d setObject:name forKey:#"Name"];
[d setObject:phone forKey:#"Phone"];
[d setObject:email forKey:#"Email"];
[Names addObject:d];
}
NSLog(#"%#",Names);
This is the NSLog of Names :
{
Email = "";
Name = Hk;
Phone = "(975)\U00a0050-1890"; //Actual Number (975)050-1890
},
{
Email = "";
Name = Nik;
Phone = "1\U00a0(234)\U00a0567-890"; //Actual Number :(932)324-1343
}
Why r unusual characters being added for Phone Number ...
Any help would be appreciated..
It is a "No-break space" (see http://unicode-table.com/en/00A0/).
It seems that such symbols can emerge in your address book via some external sync.
But I have no difference visually.
If you put in number in iPhone address book it will be automatically formatted with real unremovable space between parentheses and digits. It is not the case in your situation. You have no spaces at all visually. So in code you have no-break spaces.

Reverse strings in array objectivec [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Reverse NSString text
i am new on objectovec. i have a array having strings. how to reverse each string?
which method of NSArray and NSstring will help me out?
i want reversed string in the array.
thanks
Create a method that will return a reversed string.
-(NSString *)reverseString:(NSString *)string{
NSString *reverseString=[NSString new];
for (NSInteger i=string.length-1; i>-1; i--) {
reverseString=[reverseString stringByAppendingFormat:#"%c",[string characterAtIndex:i]];
}
return reverseString;
}
In your any of the method :
NSMutableArray *names=[NSMutableArray arrayWithObjects:#"anoop",#"johnson",#"wasim",nil];
for (NSInteger i=0; i<names.count; i++) {
names[i]=[self reverseString:names[i]];
}
NSLog(#"%#",names);
Hope this help
NSString *str=textEntered.text;//
NSMutableArray *temp=[[NSMutableArray alloc] init];
for(int i=0;i<[str length];i++)
{
[temp addObject:[NSString stringWithFormat:#"%c",[str characterAtIndex:i]]];
}
temp = [NSMutableArray arrayWithArray:[[temp reverseObjectEnumerator] allObjects]];
NSString *reverseString=#"";
for(int i=0;i<[temp count];i++)
{
reverseString=[NSString stringWithFormat:#"%#%#",reverseString,[temp objectAtIndex:i]];
}
NSLog(#"%#",reverseString);
NSString *str=textEntered.text;//
NSMutableArray *temp=[[NSMutableArray alloc] init];
for(int i=0;i<[str length];i++)
{
[temp addObject:[NSString stringWithFormat:#"%c",[str characterAtIndex:i]]];
}
temp = [NSMutableArray arrayWithArray:[[temp reverseObjectEnumerator] allObjects]];
NSString *reverseString=#"";
for(int i=0;i<[temp count];i++)
{
reverseString=[NSString stringWithFormat:#"%#%#",reverseString,[temp objectAtIndex:i]];
}
NSLog(#"%#",reverseString);
AnOther way for revers string NSStringEnumerationOptions
- (NSString *)reverseString:(NSString *)string {
NSMutableString *reversedString = [[NSMutableString alloc] init];
NSRange fullRange = [string rangeOfString:string];
NSStringEnumerationOptions enumerationOptions = (NSStringEnumerationReverse | NSStringEnumerationByComposedCharacterSequences);
[string enumerateSubstringsInRange:fullRange options:enumerationOptions usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
[reversedString appendString:substring];
}];
return reversedString;
}
Use
unichar c[yourstring.Length];
NSRange raneg={0,yourstring.Length};
[yourstring getCharacters:c range:raneg];
//c will be an array of your string do what ever you wish
Use this one to reverse your string and then store back to your array at same index.
-(NSString*)reverseString:(NSString*)string {
NSMutableString *reversedString;
int length = [string length];
reversedString = [NSMutableString stringWithCapacity:length];
while (length--) {
[reversedString appendFormat:#"%c", [string characterAtIndex:length]];
}
return reversedString;
}
But if you have mutable string then you can create a category
#interface NSMutableString (Reverse)
- (void)reverseString;
#end
#implementation NSMutableString (Reverse)
- (void)reverseString {
for (int i = 0; i < self.length/2; i++) {
int l = self.length - 1 - i;
NSRange iRange = NSMakeRange(i, 1);
NSRange lRange = NSMakeRange(l, 1);
NSString *iStr = [self substringWithRange:iRange];
NSString *lStr = [self substringWithRange:lRange];
[self replaceCharactersInRange:iRange withString:lStr];
[self replaceCharactersInRange:lRange withString:iStr];
}
}
#end
And then you can use this category method like this
NSArray *arr = [NSArray arrayWithObjects:[#"hello" mutableCopy], [#"Do it now" mutableCopy], [#"Test string, 123 123" mutableCopy], nil];
NSLog(#"%#",arr);
[arr makeObjectsPerformSelector:#selector(reverseString)];
NSLog(#"%#",arr);

Change the position of character in string

I have a two string like "SANFRANSICO" and "CHICAGO"
Now i want to make it like the string is in reverse but in a single string like "OOCGIASCNIAHRCFNAS"
I have done code but it gives me wrong result
check out my code
- (NSString *)changeString1:(NSString *)string string2:(NSString *)string2{
int first = [string length];
int second = [string2 length];
int total = first+second;
NSMutableString *str = [[NSMutableString alloc] init];
string = [self reverseString:string];
string2 = [self reverseString:string2];
for (int i=0; i<total+1; i++)
{
if (i%2==1) {
int j = i/2;
if(j < second){
NSString *ichar = [NSString stringWithFormat:#"%c", [string2 characterAtIndex:j]];
[str appendString:ichar];
}
else{
NSString *ichar = [NSString stringWithFormat:#"%c", [string characterAtIndex:j+1]];
NSLog(#"222 %d %#",j+1, ichar );
[str appendString:ichar];
check = YES;
}
}
else {
int j = i/2;
if(check == YES){
}
else{
NSString *ichar = [NSString stringWithFormat:#"%c", [string characterAtIndex:j]];
NSLog(#"1111 %d %#",j, ichar );
[str appendString:ichar];
}
}
}
return str;
}
I found the answer very soon after post this question sorry for posting this question
check out my answer
- (NSString *)changeString1:(NSString *)string string2:(NSMutableString *)string2{
int first = [string length];
int second = [string2 length];
string = [self reverseString:string];
string2 = [self reverseString:string2];
for(int i =second; i<first; i ++){
[string2 appendString:#" "];
}
int total = first*2;
NSMutableString *str = [[NSMutableString alloc] init];
for (int i=0; i<total; i++)
{
if (i%2==1) {
int j = i/2;
if(j < second){
NSString *ichar = [NSString stringWithFormat:#"%c", [string2 characterAtIndex:j]];
[str appendString:ichar];
}
}
else {
int j = i/2;
if(j < first){
NSString *ichar = [NSString stringWithFormat:#"%c", [string characterAtIndex:j]];
[str appendString:ichar];
}
else{
NSString *ichar = [NSString stringWithFormat:#"%c", [string2 characterAtIndex:j]];
[str appendString:ichar];
}
}
}
NSLog(#"str %#", str);
return str;
}

SQLITE Database Error 14

I'm developing a game where there are 4 buildings and in these buildings, there are 3 stages inside. The player can play the stages one by one, from one building to another, however, when they have finished one cycle (eg. going from building 1 stage 1 to building 4 stage 3) I keep getting this error where it's an error 14 (SQLITE_CANTOPEN) whenever the player clicks on another building. It keeps happening every single time I test the app. Can anyone help me? :S
edit: sorry, here's the code I used to open the window to access the game:
NSArray *bldgLevels = [[SQLiteManager sharedManager] fetchDataFromDatabase: MAIN_DATABASE
withQuery: SQL_STMT_GET_BUILDING_LEVELS
withValuesAndTypes: [NSArray arrayWithObjects:
[NSString stringWithFormat: #"%d", gameStateProxy.selectedArea], #"i", nil]];
NSLog(#"bldgLevels: %#", bldgLevels);
NSLog(#"getting player levels");
NSArray *playerLevels = [[SQLiteManager sharedManager] fetchDataFromDatabase: MAIN_DATABASE
withQuery: SQL_STMT_GET_PLAYER_UNLOCKED_LEVELS
withValuesAndTypes: [NSArray arrayWithObjects:
[NSString stringWithFormat: #"%d", gameStateProxy.playerId], #"i", nil]];
NSLog(#"playerLevels: %#", playerLevels);
int i = 0;
while (i < [bldgLevels count])
{
NSDictionary *bldgLevel = (NSDictionary *)[bldgLevels objectAtIndex: i];
int levelId = [(NSNumber *)[bldgLevel objectForKey: #"level_id"] intValue];
int indexOrder = [(NSNumber *)[bldgLevel objectForKey: #"index_order"] intValue];
data = [BldgLevelData createObject];
data.levelId = levelId;
data.levelName = (NSString *)[bldgLevel objectForKey: #"name"];
data.rescuedPtsRequired = [(NSNumber *)[bldgLevel objectForKey: #"rescued_required"] intValue];
data.minPtsToComplete = [(NSNumber *)[bldgLevel objectForKey: #"min_pts"] intValue];
data.lastPlayed = #"";
data.dateAdded = #"";
data.isNew = NO;
data.isCompleted = NO;
data.isLocked = YES;
// Group levels together by their index order
if (indexOrder == 1) { groupId++; }
data.groupId = groupId;
data.indexOrder = indexOrder;
int j = 0;
while (j < [playerLevels count])
{
NSDictionary *playerLevel = (NSDictionary *)[playerLevels objectAtIndex: j];
int playerLevelId = [(NSNumber *)[playerLevel objectForKey: #"level_id"] intValue];
if (levelId == playerLevelId)
{
data.rescuedHighScore = [(NSNumber *)[playerLevel objectForKey: #"rescued_highscore"] intValue];
data.rescuedScore = [(NSNumber *)[playerLevel objectForKey: #"rescued_score"] intValue];
data.lastPlayed = (NSString *)[playerLevel objectForKey: #"lastplayed"];
data.dateAdded = (NSString *)[playerLevel objectForKey: #"dateadded"];
data.isNew = ([(NSString *)[playerLevel objectForKey: #"lastplayed"] isEqualToString: #""]);
data.isCompleted = ([(NSNumber *)[playerLevel objectForKey: #"completed"] intValue] == 1);
data.isLocked = NO;
break;
}
j++;
}
if (indexOrder == 1)
{
list = [NSMutableArray arrayWithCapacity: 1];
groupData = [BldgLevelGroupData createObject];
groupData.groupId = groupId;
groupData.firstLevelId = levelId;
groupData.timeLimit = [(NSNumber *)[bldgLevel objectForKey: #"time_limit"] intValue];
groupData.list = list;
// Get SOS items
NSMutableArray *sosItems = [NSMutableArray arrayWithCapacity: 0];
//
NSLog(#"getting levelSOSItems");
NSLog(#"i: %d, j: %d", i, j);
NSLog(#"list: %#", list);
NSLog(#"levelId: %d", levelId);
NSArray *levelSOSItems = [[SQLiteManager sharedManager] fetchDataFromDatabase: MAIN_DATABASE
withQuery: SQL_STMT_GET_LEVEL_SOS
withValuesAndTypes: [NSArray arrayWithObjects:
[NSString stringWithFormat: #"%d", levelId], #"i", nil]];
NSLog(#"Levelsositems: %#", levelSOSItems);
NSLog(#"getting player sos Items");
NSArray *playerSOSItems = [[SQLiteManager sharedManager] fetchDataFromDatabase: MAIN_DATABASE
withQuery: SQL_STMT_GET_PLAYER_SOS
withValuesAndTypes: [NSArray arrayWithObjects:
[NSString stringWithFormat: #"%d", gameStateProxy.playerId], #"i",
nil]];
NSLog(#"playerSoSItems: %#", playerSOSItems);
j = 0;
while (j < [levelSOSItems count])
{
SOSItemData *sosItemData = [SOSItemData createObject];
sosItemData.itemId = [(NSNumber *)[(NSDictionary *)[levelSOSItems objectAtIndex: j] objectForKey: #"sos_id"] intValue];
sosItemData.itemName = (NSString *)[(NSDictionary *)[levelSOSItems objectAtIndex: j] objectForKey: #"name"];
sosItemData.desc = (NSString *)[(NSDictionary *)[levelSOSItems objectAtIndex: j] objectForKey: #"desc"];
sosItemData.coins = [(NSNumber *)[(NSDictionary *)[levelSOSItems objectAtIndex: j] objectForKey: #"coins_cost"] intValue];
sosItemData.cash = [(NSNumber *)[(NSDictionary *)[levelSOSItems objectAtIndex: j] objectForKey: #"cash_cost"] intValue];
sosItemData.rescuedPtsRequired = [(NSNumber *)[(NSDictionary *)[levelSOSItems objectAtIndex: j] objectForKey: #"rescued_required"] intValue];
int k = 0;
while (k < [playerSOSItems count])
{
if ([(NSNumber *)[(NSDictionary *)[playerSOSItems objectAtIndex: k] objectForKey: #"sos_id"] intValue] == sosItemData.itemId)
{
sosItemData.qty = [(NSNumber *)[(NSDictionary *)[playerSOSItems objectAtIndex: k] objectForKey: #"qty"] intValue];
break;
}
k++;
}
//NSLog(#"%#", sosItemData);
[sosItems addObject: sosItemData];
j++;
}
groupData.sosItems = sosItems;
[groupsList addObject: groupData];
}
NSLog(#"%#", data);
[list addObject: data];
i++;
}
and here's the code I used to fetch the data from the database:
-(NSArray *) fetchDataFromDatabase:(NSString *)dbPath withQuery: (NSString *)sql withValuesAndTypes: (NSArray *)params
{
/*
dbPath - Name of database file
sql - SQL statement. Prepared statements are allowed to be used here (refer to params
params - Array containing data and its corresponding data type
*/
NSMutableArray *result = nil;
//make sure db is closed
NSLog(#"close database first!");
sqlite3_close(database);
NSLog(#"open database!");
int dbStatus = [self openDatabase: dbPath];
if (dbStatus == SQLITE_OK)
{
//int stmtStatus = sqlite3_prepare_v2(database, [sql UTF8String], -1, &stmt, NULL);
int stmtStatus = [self prepareStatement: sql withParams: params];
if(stmtStatus == SQLITE_OK)
{
result = [NSMutableArray arrayWithCapacity: 1];
while(sqlite3_step(stmt) == SQLITE_ROW)
{
NSMutableDictionary *row = [NSMutableDictionary dictionaryWithCapacity: 1];
int columnCount = sqlite3_column_count(stmt);
int j = 0;
while (j < columnCount)
{
/*
Possible sqlite data types:
SQLITE_INTEGER, SQLITE_FLOAT, SQLITE_TEXT, SQLITE_BLOB, SQLITE_NULL
*/
if (sqlite3_column_type(stmt, j) == SQLITE_INTEGER)
{
[row setObject: [NSNumber numberWithInt: sqlite3_column_int(stmt, j)]
forKey: [NSString stringWithUTF8String: sqlite3_column_name(stmt, j)]];
}
else if (sqlite3_column_type(stmt, j) == SQLITE_FLOAT)
{
[row setObject: [NSNumber numberWithDouble: sqlite3_column_double(stmt, j)]
forKey: [NSString stringWithUTF8String: sqlite3_column_name(stmt, j)]];
}
else if (sqlite3_column_type(stmt, j) == SQLITE_TEXT)
{
[row setObject: [NSString stringWithFormat: #"%s", sqlite3_column_text(stmt, j)]
forKey: [NSString stringWithUTF8String: sqlite3_column_name(stmt, j)]];
}
else if (sqlite3_column_type(stmt, j) == SQLITE_NULL)
{
[row setObject: [NSNull null]
forKey: [NSString stringWithUTF8String: sqlite3_column_name(stmt, j)]];
}
j++;
}
[result addObject: row];
}
}
else { NSLog(#"stmt error: %d", stmtStatus); }
}
else if (dbStatus == 14)
{
NSLog(#"db error: %d", dbStatus);
NSLog(#"killing app.");
exit(0);
}
else { NSLog(#"db error: %d", dbStatus); }
//Even though the open call failed, close the database connection to release all the memory.
sqlite3_close(database);
return result;
}
sorry if it is wrong..... in your code you didn't finalize statement but useed stmt variable .before close DB ,we should finalize statement if we use statement.....
comment for finalize statement
sqlite3_finalize(Stmt);

Use objectForKey return wrong type of key

I'm reading a data from file that is an array of NSDictionary. With each NSDictionary include a key with name "EnglishName" and a value is type of NSString. I'm get value of a NSDictionary, create new ViewController with initialization function likes : initWithName:[(NSDictionary*)oneObjectInArray objectForKey:#"EnglishName"]; Then use NavigationController to push it.
The first time i push it-> no problem. Then press back then do it again(click to create new ViewController and push) an error appears with inform : [__NSArrayM rangeOfString:]: unrecognized selector sent to instance 0x63509a0'.
-I have checked by add a command NSLog(#"%#", [object getObjectForKey:#"EnglishName"])->error.
Then i tried to read data again in didShowView function(after back). It works without any error.
Here is the code to get data from file. Too long but maybe help to solve this problem`- (void) getListStoriesAvailable
{
[_header removeAllObjects];
SAFE_RELEASE(saveDataFromDataFile)
[storiesAvailableArray removeAllObjects];
NSString * digit = #"0123456789";
NSString * ALPHA = #"ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
for (int i = 0; i < 27; i++)
{
NSMutableArray * element = [[NSMutableArray alloc] init];
[storiesAvailableArray addObject:element];
[element release];
}
NSString * path = [NSString stringWithFormat: #"%#/data.ini",documentDirectory];
if ([[NSFileManager defaultManager] fileExistsAtPath:path])
{
saveDataFromDataFile = [[NSMutableArray alloc] initWithContentsOfFile:path];
for (int i = 0; i < [saveDataFromDataFile count]; i++)
[[saveDataFromDataFile objectAtIndex:i] setObject:#"NO" forKey:#"Downloading"];
for (int i = 0; i < [saveDataFromDataFile count]; i++)
{
NSDictionary * theStory = [saveDataFromDataFile objectAtIndex:i];
NSString * word = [theStory objectForKey:#"EnglishName"];
if ([word length] == 0) continue;
NSString * firstCharacter = [[word substringToIndex: 1] uppercaseString];
NSRange range;
//The special case when the name of story start with a digit, add the story into "0-9" header and index
range = [digit rangeOfString:firstCharacter];
if (range.location != NSNotFound)
{
[[storiesAvailableArray objectAtIndex:0] addObject:theStory];
continue;
}
//Check the index of the first character
range = [ALPHA rangeOfString:firstCharacter];
if (range.location != NSNotFound)
{
[[storiesAvailableArray objectAtIndex:(range.location + 1)] addObject:theStory];
continue;
}
}
}
NSMutableArray * temp = [[NSMutableArray alloc] init];
for (int i = 0; i < [storiesAvailableArray count]; i++)
{
if ([[storiesAvailableArray objectAtIndex:i] count] != 0)
{
[_header addObject:[ALPHA_ARRAY objectAtIndex:i]];
[temp addObject:[storiesAvailableArray objectAtIndex:i]];
}
}
[storiesAvailableArray removeAllObjects];
for (int i = 0; i < [temp count]; i++)
[storiesAvailableArray addObject:[temp objectAtIndex:i]];
//storiesAvailableArray = temp;
[temp release];
}
`
And there is code to get NSDictionary
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
currentTable = tableView;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSInteger row = [indexPath row];
NSDictionary * story;
if (tableView == listStoriesAvailable) story = [[storiesAvailableArray objectAtIndex:[indexPath section]] objectAtIndex:row];
_storyDetail = [[StoryViewController alloc] initWithName:[story objectForKey:#"EnglishName"]];
[self.navigationController setDelegate:self];
[self.navigationController pushViewController:_storyDetail animated:YES];
}
So what is problem ? Pls help!
You're not retaining your dictionary.
Please edit your question and add the code where your NSDictionary gets created.