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 > PHP > PHP Forum > iOS - ทำUIAlertView แต่มันโชว์ข้อมูลเป็นJson Array ค่ะ ไม่ทราบเป็นเพราะอะไรแล้วจะแปลง json เป็นข้อความยังงัยค่ะ



 

iOS - ทำUIAlertView แต่มันโชว์ข้อมูลเป็นJson Array ค่ะ ไม่ทราบเป็นเพราะอะไรแล้วจะแปลง json เป็นข้อความยังงัยค่ะ

 



Topic : 106904

Guest




ทำUIAlertView แต่มันโชว์ข้อมูลเป็นJson Array ค่ะ ไม่ทราบเป็นเพราะอะไรแล้วจะแปลง json เป็นข้อความยังงัยค่ะ
AlertView

Code (Objective-C)
//
//  SearchView.m
//  Liberry
//
//  Created by Nakornjinda on 1/15/2557 BE.
//  Copyright (c) 2557 Nakornjinda. All rights reserved.
//

#import "SearchView.h"
#import "Loginoneview.h"



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


@end

@implementation SearchView
- (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
   
    NSString * UserSelected;
    
    {
        
        NSDictionary *tmpDict = [displayObject objectAtIndex:indexPath.row];
        
        
        
        UserSelected =[displayObject objectAtIndex:indexPath.row];
        
        NSString * book;
        
        book = [tmpDict objectForKey:title1];
        
        
        
        
        
    }
    
    NSString*str = [[NSString alloc]initWithFormat:@"รายละเอียดหนังสือ: %@",UserSelected];
    
    
    
    UIAlertView *alv = [[UIAlertView alloc]
                        
                        initWithTitle:@"รายการที่เลือก"
                        
                        message:str
                        
                        delegate:nil
                        
                        cancelButtonTitle:nil
                        
                        otherButtonTitles:@"OK", nil];
    
    [alv show];
    

}

/*
 // 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;
 }
 */

- (IBAction)BackToViewController:(id)sender {
    [self dismissViewControllerAnimated:YES completion:NULL];
    
}  //โค้ดติดต่ดปุ่มกลับหน้า
- (IBAction)gotoLoginoneview:(id)sender {
   Loginoneview *view2 = [[Loginoneview alloc] initWithNibName:nil bundle:nil];
    [self presentViewController:view2 animated:NO completion:NULL];
} //โค้ดไปหน้า OneViewController *view1



@end




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







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-03-14 14:51:07 By : fern_105 View : 882 Reply : 2
 

 

No. 1



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

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

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

แปลงค่า JSON ก่อนครับ



iOS/iPhone and JSON (Create JSON and JSON Parsing, Objective-C)







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


 

No. 2

Guest


ต้องใส่ตรงบันทัดไหนค่ะ ลองใส่แล้วมัน error ค่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-03-15 08:32:57 By : fern_105
 

   

ค้นหาข้อมูล


   
 

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