|
![](/images/resource/spacer.gif) |
|
How to NSMutableArray value pass from NSObject to UIViewController in ios ? |
|
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
NSObject.h
Code (Objective-C)
#import <Foundation/Foundation.h>
@interface InvitationList : NSObject
@property (nonatomic, retain) NSMutableArray *myObject;
@property (nonatomic, retain) NSMutableArray *displayObject;
@property (nonatomic, retain) NSDictionary *dict;
@property (nonatomic, retain) NSString *event_id;
@property (nonatomic, retain) NSString *eventname_inv;
@property (nonatomic, retain) NSString *location_inv;
@property (nonatomic, retain) NSString *date_inv;
@property (nonatomic, retain) NSString *image_url;
@property(nonatomic,assign) NSMutableData *receivedData;
-(void)fnPost:(NSString*)pStrVale;
-(NSString *)postMethos;
-(NSMutableArray *)postMethods;
@end
NSObject.m
Code (Objective-C)
#import "InvitationList.h"
@implementation InvitationList
@synthesize event_id,eventname_inv,location_inv,date_inv,image_url;
@synthesize myObject,displayObject,dict;
@synthesize receivedData;
//@synthesize eventname_inv;
-(void)fnPost:(NSString*)pStrVale{
event_id = @"eei_event_id";
eventname_inv = @"ee_event_name";
location_inv = @"ee_address";
date_inv = @"ees_event_date";
image_url = @"ee_event_image_url";
// event_id = @"123";
// eventname_inv = @"sample";
myObject = [[NSMutableArray alloc] init];
NSMutableString *post = [NSMutableString stringWithFormat:@"sUserId=%@",pStrVale];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/InvitationList.php",kBaseURL]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (theConnection) {
self.receivedData = [[NSMutableData data] retain];
//To show the Indicator
}else{
NSLog(@"Connection lost!: Failed to load data");
}
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[receivedData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[receivedData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
// inform the user
NSLog(@"Connection failed! Error - %@ %@",[error localizedDescription],[[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
if (receivedData) {
@try{
id jsonObjects = [NSJSONSerialization JSONObjectWithData:receivedData options:NSJSONReadingMutableContainers error:nil];
// values in foreach loop
for (NSDictionary *dataDict in jsonObjects) {
NSString *str_event_id = [dataDict objectForKey:@"eei_event_id"];
NSString *str_event_name = [dataDict objectForKey:@"ee_event_name"];
NSString *str_location = [dataDict objectForKey:@"ee_address"];
NSString *str_date = [dataDict objectForKey:@"ees_event_date"];
NSString *str_image_url = [dataDict objectForKey:@"ee_event_image_url"];
dict = [NSDictionary dictionaryWithObjectsAndKeys:
str_event_id, event_id,
str_event_name, eventname_inv,
str_location, location_inv,
str_date, date_inv,
str_image_url, image_url,
nil];
[myObject addObject:dict];
}
//displayObject =[[NSMutableArray alloc] initWithArray:myObject];
displayObject = [[NSMutableArray alloc] initWithArray:myObject];
// [items postMethods];
}
@catch (NSException *exception) {
NSLog(@"exception error %@", exception);
}
@finally {
// Call After working function
}
}
}
Here, How to displayobject value pass to UIViewController
Tag : Mobile, iOS, iPhone, Objective-C
![](/images/adv.jpg?v=1001)
|
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-11-24 17:30:22 |
By :
vishwa |
View :
1085 |
Reply :
2 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
Thanks mr.win
How can i will pass that object to viewcontroller
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2014-11-25 16:42:43 |
By :
vishwa |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
|
|
|
![](/images/digitalocean-banner.jpg)
|
Load balance : Server 05
|