배열에서 선택한 데이터를로드하고 사용자 선택에 따라 변경하는 iphone 탭을 만드는 방법.iphone 즐겨 찾기 탭 만들기
답변
ALX는
간단한 시나리오는 만들 수있을 것 NIB 기반 UITableViewCell
(이것 밖에 자습서의 많음이있다) 어떤 종류의 그것에 레이블이있다. 당신은 사용자가 셀을 선택하고 다음이 NSUserDefaults
에 저장됩니다 변경 가능한 배열로 그 저장할 때 다음 라벨의 내용을 잡고있다 수행 할 수있는
.
그런 다음 다른보기에서 NSUserDefaults
에 액세스하여 묻는 것처럼 "즐겨 찾기"탭을 채울 수 있습니다.
약간의 샘플 코드가 도움이됩니다 (이전 질문에서 말한 것처럼 원래 데이터가 UITableView에 있다고 가정). 이 코드를 내 머리 부분 (테스트되지 않은 코드)에서 작성하므로 모든 버그를 해결해야하지만 아이디어는 정확합니다. 새 뷰 컨트롤러에 일단
// in the .h file
#import <UIKit/UIKit.h>
@interface MyViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
// set up a mutable array which allows editing of the array
NSMutableArray *myFavoritesData;
}
// set up a retained property
@property (nonatomic, retain) NSMutableArray *myFavoritesData;
@end
// in the .m file
// synthesize the getters/setters for your array
@synthesize myFavoritesData;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// find cell that was just pressed
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
// get pointer for the label that we want to identify the cell by
// the tag in this case is set to '5' in Interface Builder in the options for the label
UILabel *someLabel;
someLabel = (UILabel *)[cell viewWithTag:5];
NSString *tmpFavorite = someLabel.text;
// get the count of the current array and use that for the "new" row since the count
// will always be 1 larger than the last object in the array (arrays start at 0, counts start at 1)
NSUInteger newRow = [self.myFavoritesData count];
[self.myFavoritesData insertObject:tmpFavorite atIndex:newRow];
}
// save the mutable array into NSUserDefaults when the view is about to disappear
- (void) viewWillDisappear:(BOOL)animated
{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:self.myFavoritesData forKey:@"MyFavorites"];
// synchronize the data now instead of waiting for the OS to synchronize it at some
// arbitrary time in the future
[userDefaults synchronize];
}
, 당신은 단지 NSUserDefaults
읽고 배열에서 테이블을 채울 수 있습니다. 예를 들어 :
// favorites view controller
- (void)viewDidLoad {
[super viewDidLoad];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSMutableArray *tmpArray = [[NSMutableArray alloc] init];
tmpArray = [[userDefaults objectForKey:@"MyFavorites"] mutableCopy];
if ([tmpArray count] == 0) {
//
// no favorites have ever been saved
//
} else {
// load the favorites into some array you synthesized just like before
self.tableFavoritesData = [[NSMutableArray alloc] init];
self.tableFavoritesData = [[userDefaults objectForKey:@"MyFavorites"] mutableCopy];
NSLog(@"favorites data is %d and %@", [self.tableFavoritesData count], self.tableFavoritesData);
}
[tmpArray release];
}
그런 다음 즐겨 찾기의 cellForRowAtIndexPath
방금 배열의 각 인덱스에 각 문자열에 액세스 컨트롤러를 볼 당신 (그래서, 인덱스 0에 대한 문자열이 행 0으로 갈 것에, 인덱스 1 문자열로 갈 것 1 행 등) 그리고 이것은 당신이 좋아하는 테이블을 채울 것입니다!
사용해보세요.
덕분에 많은 인스턴트 메신저의 구조를 얻었습니다. 하나의 작은 문제 임에도 불구하고 세포 내용물을 얻고 싶지 않습니다. 나는 셀에 의해 보여지는 뷰의 내용을 얻고 싶다. 이 코드를 변경해야 할 것 같습니다. UILabel * someLabel; someLabel = (UILabel *) [cell viewWithTag : 5]; NSString * tmpFavorite = someLabel.text; ? 나는 ([[rootArray objectAtIndex : indexPath] set]; 을 사용하려고했으나 실제로는 작동하지 않았다. :( –
) 어떻게'rootArray'가 정의 되었는가? 위의 변경 가능한 배열을 어떻게 정의했는지와 비슷한 경우, '[self.rootArray objectAtIndex.indexPath.row];''indexPath.row'는 int이고 눌려진 현재 행을 지정합니다. – iwasrobbed
- 1. 즐겨 찾기 탭 추가 방법
- 2. iPhone 핵심 데이터가없는 즐겨 찾기 목록 구현?
- 3. 즐겨 찾기 목록을 만드는 방법
- 4. 주소창의 즐겨 찾기 아이콘
- 5. IE 7+ 즐겨 찾기
- 6. 병합 Facebook 즐겨 찾기
- 7. 사용자 즐겨 찾기 저장
- 8. flickr 즐겨 찾기 검색
- 9. 즐겨 찾기 아약스 페이지
- 10. 안드로이드의 기본 다이얼러에서 즐겨 찾기 탭과 같은 목록보기 만들기
- 11. AJAX를 사용하여 Gmail 스타일 별 즐겨 찾기 아이콘 만들기
- 12. .vbs 즐겨 찾기 목록을 정렬하려면
- 13. Android에서 즐겨 찾기 가져 오기
- 14. 내 즐겨 찾기 Segfault !! 왜?
- 15. 연락처 즐겨 찾기 검색 창
- 16. 기사에 대한 즐겨 찾기 버튼
- 17. iPhone 즐겨 찾기 링크 홈 화면에 추가 하시겠습니까?
- 18. iPhone 응용 프로그램의 즐겨 찾기 탭을 만드는 방법은 무엇입니까?
- 19. iPhone 응용 프로그램의 즐겨 찾기 연락처 목록에 어떻게 액세스합니까?
- 20. 셰어 포인트 사용자 즐겨 찾기 문서
- 21. NSUserDefaults가 즐겨 찾기 목록을 저장할 올바른 위치입니까?
- 22. 오픈 소스 사회 즐겨 찾기 CMS?
- 23. 즐겨 찾기 개체의 배열에 개체 추가
- 24. CouchDB에서 사용자 등급/즐겨 찾기 구현하기
- 25. 데이터베이스 설계 : 선택 및 제한 즐겨 찾기
- 26. 내 즐겨 찾기 목록에서 페이지를 삭제하십시오. (PHP)
- 27. 트위터 즐겨 찾기 및 20 개 이상의
- 28. Internet Explorer의 즐겨 찾기 파일을 덤프하십시오.
- 29. "즐겨 찾기"를 Rails 쿠키에 저장하고 있습니까?
- 30. MySQL은 : 없음 독특한 테이블/별칭 : '즐겨 찾기'
가능합니다. 그러나 귀하의 질문은 너무 모호합니다. –