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,027

HOME > Mobile > Mobile Forum > iOS - ตอนนี้ทำหน้า search อยู่ค่ะต้องการทำหน้า detail หนังสือ แต่มันยังerror อยู่ค่ะไม่ทราบว่าโค้ดผิดตรงไหนมั้ยค่ะหาไม่เจอ



 

iOS - ตอนนี้ทำหน้า search อยู่ค่ะต้องการทำหน้า detail หนังสือ แต่มันยังerror อยู่ค่ะไม่ทราบว่าโค้ดผิดตรงไหนมั้ยค่ะหาไม่เจอ

 



Topic : 106630

Guest




พอแตะที่ชื่อหนังสือเพื่อไปหน้ารายละเอียดหนังสือแล้วมันขึ้น error เหมือนไม่ส่งค่าไปหน้า detail ค่ะแต่ไม่รู้ว่าโค้ดผิดตรงไหนค่ะรบกวนผู้รู้ด้วยน่ะค่ะ
error ค่ะ

MasterViewController.h

Code (Objective-C)
#import <UIKit/UIKit.h>

@interface MasterViewController : UITableViewController<UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate>


@property (strong, nonatomic) IBOutlet UITableView *tableData;
@property(nonatomic,assign) NSMutableData *receivedData;



@end



MasterViewController.m

Code (Objective-C)

#import "MasterViewController.h"

#import "DetailViewController.h"

@interface MasterViewController ()
    {
        
        NSMutableArray *allObject;
        NSMutableArray *displayObject;
        
        // A dictionary object
        NSDictionary *dict;
        
        // Define keys
        NSString *idbook;
        NSString *title1;
        NSString *access;
        NSString *w_name;
        NSString *status;
        NSString *bcontent;
    }


@end

@implementation MasterViewController


- (void)awakeFromNib
{
    [super awakeFromNib];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Define keys
    idbook = @"Idbook";
    title1 = @"title1";
    access = @"access";
    w_name = @"w_name";
    status= @"status1";
    bcontent=@"content";
    
    
    // Create array to hold dictionaries
    allObject = [[NSMutableArray alloc] init];
    
    NSData *jsonData = [NSData dataWithContentsOfURL:
                        [NSURL URLWithString:@"http://localhost:8888/searchtest.php"]];
    
    id jsonObjects = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
    
    // values in foreach loop
    for (NSDictionary *dataDict in jsonObjects) {
        NSString *strIdbook = [dataDict objectForKey:@"Idbook"];
        NSString *strtitle1 = [dataDict objectForKey:@"title1"];
        NSString *straccess = [dataDict objectForKey:@"access"];
        NSString *strw_name= [dataDict objectForKey:@"w_name"];
        NSString *strstatus1= [dataDict objectForKey:@"status1"];
        NSString *strcontent= [dataDict objectForKey:@"content"];
        dict = [NSDictionary dictionaryWithObjectsAndKeys:
                strIdbook, idbook,
                strtitle1, title1,
                straccess, access,
                strw_name, w_name,
                strstatus1,status,
                strcontent,bcontent,
                nil];
        [allObject addObject:dict];
    }
    
    displayObject =[[NSMutableArray alloc] initWithArray:allObject];
	// Do any additional setup after loading the view, typically from a nib.
   }

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - Table View

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return displayObject.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        // Use the default cell style.
        cell = [[UITableViewCell alloc] initWithStyle : UITableViewCellStyleSubtitle
                                      reuseIdentifier : CellIdentifier];
    }
    
    
    NSDictionary *tmpDict = [displayObject objectAtIndex:indexPath.row];
    
    NSString *cellValue;
    cellValue = [tmpDict objectForKey:title1];
    NSString* detailbook;
    detailbook = [NSString stringWithFormat:@"รหัส%@ , ผู้แต่ง %@,  สถานะ  %@ "
                  ,[tmpDict objectForKey:access]
                  ,[tmpDict objectForKey:w_name]
                  ,[tmpDict objectForKey:status]];
    
    cell.textLabel.text = cellValue;
    cell.detailTextLabel.text= detailbook;
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
    
    
    
}

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    
    if([searchString length] == 0)
    {
        [displayObject removeAllObjects];
        [displayObject addObjectsFromArray:allObject];
    }
    else
    {
        [displayObject removeAllObjects];
        for(NSDictionary *tmpDict in allObject)
        {
            NSString *val = [tmpDict objectForKey:title1];
            
            NSRange r = [val rangeOfString:searchString options:NSCaseInsensitiveSearch];
            if(r.location != NSNotFound)
            {
                [displayObject addObject:tmpDict];
            }
        }
    }
    
    return YES;
}


- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
    searchBar.text=@"";
    
    [searchBar setShowsCancelButton:NO animated:YES];
    [searchBar resignFirstResponder];
}



- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}

#pragma mark - TableView Delegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Perform segue to candy detail
    [self performSegueWithIdentifier:@"candyDetail" sender:tableView];
}

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

#pragma mark - Segue
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"lodgedetail"]) {
       
        
        NSIndexPath * indexpath = [self.tableView indexPathForSelectedRow];
        NSDictionary *tmpDict = [allObject objectAtIndex:indexpath.row];
        
        
     [[segue destinationViewController] setNameItem:[tmpDict objectForKey:title1]];
    [[segue destinationViewController] setAccessItem:[tmpDict objectForKey:access]];
    [[segue destinationViewController] setDetailItem:[tmpDict objectForKey:bcontent]];
        
        
              }
}

@end


DetailViewController.h

Code (Objective-C)
#import <UIKit/UIKit.h>

@interface DetailViewController : UIViewController
{
 IBOutlet UILabel *namebook;
 IBOutlet UILabel *accessbook;
 IBOutlet UILabel *detailbook;
}
@property (strong, nonatomic) id detailItem;
@property(strong,nonatomic) id nameItem;
@property(strong,nonatomic) id accessItem;

-(void)setNameItem:(id)newtitle1;
-(void)setAccessItem:(id)newaccess;
-(void)setDetailItem:(id)newbcontent;

@end



DetailViewController.m

Code (Objective-C)
#import "DetailViewController.h"


@interface DetailViewController ()

@end

@implementation DetailViewController
@synthesize detailItem,accessItem,nameItem;
#pragma mark - Managing the detail item


- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
   namebook.text = [nameItem description];
   accessbook.text = [accessItem description];
   detailbook.text = [detailItem description];
}
-(void)setNameItem:(id)newtitle1
{
    nameItem = newtitle1;

}
-(void)setAccessItem:(id)newaccess
{
    accessItem = newaccess;

}
-(void)setDetailItem:(id)newbcontent
{

    detailItem = newbcontent;
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)dealloc{
    [namebook release];
    [accessbook release];
    [detailbook release];
    [super dealloc];
}
@end





Tag : Mobile, MySQL, iOS, iPhone, Objective-C, Mac







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-03-07 00:46:01 By : fern_105 View : 982 Reply : 3
 

 

No. 1



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

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

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

คงจะต้องได้นั่ง Debug ดูแล้วครับว่า Error ตรงไหน






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-03-07 09:26:34 By : mr.win
 


 

No. 2



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



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


ลองดูที่การผูกของในหน้า Story ว่าผูกครบไหม ตัว View หลุดไหม แล้วก็ลองนั่ง Debug ตั้งแต่ตอนที่เริ่มแตะไปอะครับว่ามันถึงตรงไหนแล้วเกิด Error ครับ :)
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-03-07 13:59:03 By : thannam001
 

 

No. 3



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

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

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

น่าจะผิดตอนที่เชื่อมพวก IBOutlet ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-03-08 06:59:51 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : iOS - ตอนนี้ทำหน้า search อยู่ค่ะต้องการทำหน้า detail หนังสือ แต่มันยังerror อยู่ค่ะไม่ทราบว่าโค้ดผิดตรงไหนมั้ยค่ะหาไม่เจอ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 01
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 อัตราราคา คลิกที่นี่