//// section이 복수일때


   //table에 뿌려줄 데이터 sec1, sec2 -> table data

    NSArray *sec1 = [[NSArray alloc] initWithObjects:@"sec1-row1",@"sec1-row2",@"sec1-row3", nil];

    NSArray *sec2 = [[NSArray alloc] initWithObjects:@"sec2-row1",@"sec2-row2", nil];

    

    tabledata = [[NSArray alloc] initWithObjects:sec1,sec2, nil];


...




// cell 세팅

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    

    // Configure the cell...

    

    if(cell == nil){

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    }


    if(indexPath.section == 0){

        cell.textLabel.text = [[tabledata objectAtIndex:0] objectAtIndex:indexPath.row];

    }else if(indexPath.section == 1){

        cell.textLabel.text = [[tabledata objectAtIndex:1] objectAtIndex:indexPath.row];

    }

    

    return cell;

}


//section 갯수

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

#warning Potentially incomplete method implementation.

    // Return the number of sections.

    return self.tabledata.count;

}


// Record 갯수 (section별로)

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

#warning Incomplete method implementation.

    // Return the number of rows in the section.

    

    if(section == 0){

        return [[self.tabledata objectAtIndex:0] count];

    }else if(section == 1){

        return [[self.tabledata objectAtIndex:1] count];        

        

    }

    

}



// Header와 Footer

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

    if(section == 0){

        return @"section1";

    }else{

        return @"Section2";

    }

}



- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {

    if(section == 0){

        return @"section1";

    }else{

        return @"Section2";

    }

}


Posted by tenn
,

[obj-c] View 이동

iPhone 2012. 4. 13. 12:01



Push


UIViewController *detailViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailView"];

//스토리보드에서 식별자 DetailView인 컨트롤러에 포인터 지정


[self.navigationController pushViewController:detailViewController animated:true];

//push로 뷰이동



Modal에서 돌아가기


[self dismissModalViewControllerAnimated:YES];


Posted by tenn
,

[obj-c] File

iPhone 2012. 4. 6. 17:34


//// 어플리케이션의 하위디렉터리
Documents
Library
tmp

NSTemporaryDirectory();  //tmp디렉터리 경로

if([[NSFileManager defaultManager] fileExistsAtPath:filePath]){}  //파일 존재여부 확인

NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Apps" ofType:@"plist"];
//Resources폴더에서 프로퍼티 리스트 로드

//File Path = app's documents folder

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectoryNSUserDomainMaskYES);

      NSString *documentsDir = [paths objectAtIndex:0];

      NSString *fileName = 

            [documentsDir stringByAppendingPathComponent:@"data2.txt"];


//File write

    NSMutableArray *array = [[NSMutableArray allocinit];

    [array addObject:@"Text1"];

    [array addObject:@"Text2"];

    [array writeToFile:fileName atomically:YES];  



//File read

if ([[NSFileManager defaultManagerfileExistsAtPath:fileName]){

        NSArray *array = [[NSArray allocinitWithContentsOfFile: fileName];

        NSLog(@"%@",array);

 }

//// Image File Save



- (IBAction)saveAction:(id)sender {

    NSMutableArray *array = [[NSMutableArray alloc] init];

    [array addObject:UIImagePNGRepresentation(self.imageView.image)];

    [array writeToFile:self.fileName atomically:YES];  

    ALERT(@"FileSave", @"Image Saved.");

}


- (IBAction)loadAction:(id)sender {

    if ([[NSFileManager defaultManager] fileExistsAtPath:fileName]){

        NSArray *array = [[NSArray alloc] initWithContentsOfFile: fileName];

        UIImage *image = [UIImage imageWithData:[array objectAtIndex:0]];

        self.imageView.image = image;

    }




Posted by tenn
,