Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,025

HOME > Mobile > Mobile Forum > iOS ขอคำปรึกษาครับ เรื่อง TableView => ViewController มันส่งค่าไอดี ไปให้ ViewController ผิดครับ ช่วยแก้ไขหน่อยครับ



 

iOS ขอคำปรึกษาครับ เรื่อง TableView => ViewController มันส่งค่าไอดี ไปให้ ViewController ผิดครับ ช่วยแก้ไขหน่อยครับ

 



Topic : 089854



โพสกระทู้ ( 1 )
บทความ ( 0 )



สถานะออฟไลน์




มีปัญหาเวลาส่งค่าไปอีก หน้านึงครับ

คือใช้ ตัว 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







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-01-27 15:26:20 By : manutnarakss View : 1138 Reply : 1
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ลองดูครับ



Go to : iOS/iPhone TableView Passing Data to Another View (Objective-C,iPhone,iPad)






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-01-28 20:38:12 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : iOS ขอคำปรึกษาครับ เรื่อง TableView => ViewController มันส่งค่าไอดี ไปให้ ViewController ผิดครับ ช่วยแก้ไขหน่อยครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่