|
|
|
iOS ขอคำปรึกษาครับ เรื่อง TableView => ViewController มันส่งค่าไอดี ไปให้ ViewController ผิดครับ ช่วยแก้ไขหน่อยครับ |
|
|
|
|
|
|
|
มีปัญหาเวลาส่งค่าไปอีก หน้านึงครับ
คือใช้ ตัว UISearchBar ค้นหาอะครับ มันขึ้นผลการค้นหาก็จริง แต่พอกด เข้าไปที่ row มันส่งเฉพาะค่า id ของบรรทัดแรกที่ค้นหาเจอไปครับ แทนที่จะส่งค่า id ของบรรทัดที่กดไป ต้องแก้ไขยังไงครับ ขอบคุณมากครับ
Code (Objective-C)
@implementation Table1Controller
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
InsideController *controller = [segue destinationViewController];
NSDictionary *dic = [lists objectAtIndex:indexPath.row];
controller.myIndex = [[dic objectForKey:@"id"] intValue];
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//Navigation bar color
[self.navigationController.navigationBar setTintColor:[UIColor lightGrayColor]];
NSString *path = [[NSBundle mainBundle] pathForResource:@"contact" ofType:@"sqlite"];
FMDatabase *database = [FMDatabase databaseWithPath:path];
[database open];
FMResultSet *rs = [database executeQuery:@"select * from Contact"];
lists = [NSMutableArray array];
while ([rs next]) {
NSDictionary *dic = [rs resultDictionary];
[lists addObject:dic];
}
[lists retain];
[self.tableView reloadData];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [lists count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
Cell3rows *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSDictionary *dic = [lists objectAtIndex:indexPath.row];
cell.disId.text = [NSString stringWithFormat:@"%@ ", [dic objectForKey:@"id"]]; //[dic objectForKey:@"id"];
cell.disFname.text = [NSString stringWithFormat:@"%@ %@", [dic objectForKey:@"fname"],[NSString stringWithFormat:@"%@ ", [dic objectForKey:@"lname"]]];
cell.disLname.text = [dic objectForKey:@"nname"];
//Set IMG
//NSString *imgpath = [[NSBundle mainBundle] bundlePath];
//imgpath = [imgpath stringByAppendingFormat:@"/%@",[dic objectForKey:@"picture"]];
//cell.thumb.image = [UIImage imageWithContentsOfFile:imgpath];
return cell;
}
#pragma mark - Table view delegate
/*- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"IndexPath: %@", [indexPath description]);
NSLog(@"Row Selected = %i",indexPath.row);
}*/
- (void)awakeFromNib
{
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (IBAction)revealMenu:(id)sender
{
[self.slidingViewController anchorTopViewTo:ECRight];
}
//Search
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
//Adding
NSString *path = [[NSBundle mainBundle] pathForResource:@"contact" ofType:@"sqlite"];
FMDatabase *database = [FMDatabase databaseWithPath:path];
[database open];
NSString *per = @"%%";
if([searchString length] == 0)
{
FMResultSet *rs = [database executeQuery:@"select * from Contact"];
lists = [NSMutableArray array];
while ([rs next]) {
NSDictionary *dic = [rs resultDictionary];
[lists addObject:dic];
}
[lists retain];
[self.tableView reloadData];
}
else
{
FMResultSet *rs = [database executeQuery:[NSString stringWithFormat:@"select * from Contact where id LIKE '%@%@%@' OR nname LIKE '%@%@%@' OR fname LIKE '%@%@%@' OR lname LIKE '%@%@%@'",per, searchString,per,per, searchString,per,per, searchString,per,per, searchString,per]];
lists = [NSMutableArray array];
while ([rs next]) {
NSDictionary *dic = [rs resultDictionary];
[lists addObject:dic];
}
[lists retain];
[self.tableView reloadData];
//NSLog([NSString stringWithFormat:@"select * from Contact where id LIKE '%@%@%@'",per, searchString,per]);
}
return YES;
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
searchBar.text=@"";
[searchBar setShowsCancelButton:NO animated:YES];
[searchBar resignFirstResponder];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 67;
}
Tag : Mobile, iOS
|
|
|
|
|
|
Date :
2013-01-27 15:26:20 |
By :
manutnarakss |
View :
1221 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|