.h File:
NSArray *state;
NSArray *state;
NSMutableArray *components;
.m File:
-(Void) ButtonCoding
{
NSString *Filename=@"StateList";
NSString* path = [[NSBundle mainBundle] pathForResource:Filename
ofType:@"txt"];
NSString* content = [NSString stringWithContentsOfFile:path
encoding:NSUTF8StringEncoding
error:NULL];
NSArray *componet=[[NSMutableArray alloc]init];
state=[[NSMutableArray alloc]init];
componet = [content componentsSeparatedByString:@"|"];
for(int k=0;k<[componet count]-1;k++)
{
NSString *name1 = [componet objectAtIndex:k];
[state addObject:name1];
}
[table2 reloadData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if(tableView == self.tabel1)
{
return 1;
}
else if(tableView == self.tabel2)
{
return 1;
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
if (tableView == self.tabel1)
{
return [city count];
}
else if (tableView == self.tabel2)
{
return [state count];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if(tableView == self.tabel1)
{
NSString *cellValue1 = [city objectAtIndex:indexPath.row];
cell.text = cellValue1;
}
else if(tableView == self.tabel2)
{
NSString *cellValue2 = [state objectAtIndex:indexPath.row];
cell.text = cellValue2;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == self.tabel1)
{
NSString *CitySelected = [city objectAtIndex:indexPath.row];
txt1.text=CitySelected;
tabel1.hidden=YES;
}
else if (tableView == self.tabel2)
{
NSString *StateSelected = [state objectAtIndex:indexPath.row];
txt2.text=StateSelected;
tabel2.hidden=YES;
}
}
No comments:
Post a Comment