В моем приложении у меня есть страница входа, на которой пользователь может войти. Как только пользователь вошел в свою учетную запись, он должен перейти на свою страницу панели инструментов (домашняя страница).
На странице панели инструментов естьтри кнопки add , edit и logout , но на странице панели управления я вызываю URL, чтобы прочитать файл XML из метода viewDidLoad
, прежде чем нажимать любую кнопку.
Я хочу проанализировать файл XML и сохранить его значение на той же странице.
Я попытался проанализировать файл XML на странице сохранения, и я использую значение файла XML на той же странице.странице, но я не могу использовать это строковое значение в другой функции на той же странице.но я не могу использовать строку user_login_xml
в вышеуказанном методе, которая находится на той же странице .. вместо этого я получаю ошибку exc_bad_access
- (void)viewDidLoad
{
NSString *EditProfileID=Dataid;
NSString* result = [EditProfileID stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSString *urlAsString =[NSString stringWithFormat:@"http://www.mybusinesscentral.co.uk/mobile/iphone_profile_id.php?id="];
urlAsString=[urlAsString stringByAppendingString:result];
NSURLRequest *req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:urlAsString]];
urlCon = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if (urlCon)
{
NSMutableData *mutableData = [[NSMutableData alloc] init];
self.receivedData=mutableData;
[mutableData release];
}
else //connection failed.
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"Error", @"Error")
message:NSLocalizedString(@"Error connecting to remote server", @"Error connecting to remote server")delegate:self cancelButtonTitle:NSLocalizedString(@"Ok", @"Ok") otherButtonTitles:nil];
[alert show];
[alert release];
}
[req release];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[receivedData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data1
{
[receivedData appendData:data1];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[connection release];
self.receivedData = nil;
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Error"
message:[NSString stringWithFormat:@"Connection failed! Error - %@ (URL: %@)", [error localizedDescription],[[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]]
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
[alert release];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *receivedDataAsString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
[receivedDataAsString release];
xmlParser = [[NSXMLParser alloc] initWithData:receivedData];
[xmlParser setDelegate:self];
[xmlParser parse];
[connection release];
self.receivedData = nil;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqualToString:@"details"])
{
NSString *user_login = [attributeDict objectForKey:@"user_login"];
user_login_xml = [NSString stringWithFormat:@"%@",user_login];
}
}
-(IBAction)Btn_AddNew:(id)sender
{
if ([user_login_xml length]==0)
{
AddNew *addnew = [[AddNew alloc]initWithNibName:@"AddNew" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:addnew animated:YES];
}
else
{
SubmitYourListing_Active *SubmitListing=[[SubmitYourListing_Active alloc] initWithNibName:@"SubmitYourListing_Active" bundle:[NSBundle mainBundle]];
SubmitListing.UserID=Dataid;
[self.navigationController pushViewController:SubmitListing animated:YES];
}
}