update: 2011/12/02
A. 開啟 ArticleViewController.h 檔案, 修改如下:
#import <UIKit/UIKit.h>
@interface ArticleViewController : UIViewController {
//@add
IBOutlet UILabel *titleLabel; // article 標題
IBOutlet UILabel *subTitleLabel; // article 副標題
IBOutlet UITextView *contentText; // article 內容
NSManagedObject *article; // represents the current article
}
//@add
@property (nonatomic, retain) IBOutlet UILabel *titleLabel;
@property (nonatomic, retain) IBOutlet UILabel *subTitleLabel;
@property (nonatomic, retain) IBOutlet UITextView *contentText;
@property (nonatomic, retain) NSManagedObject *article;
@end
----------------------------------------------------------------------------------------------------------
B. 開啟 ArticleViewController.m 檔案, 修改如下:
@synthesize titleLabel, subTitleLabel, contentText, article;
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.titleLabel = nil;
self.subTitleLabel = nil;
self.contentText = nil;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
if (article != nil) {
titleLabel.text = [article valueForKey:@"title"];
subTitleLabel.text = [article valueForKey:@"subTitle"];
contentText.text = [article valueForKey:@"content"];
titleLabel.textColor = [UIColor darkGrayColor];
subTitleLabel.textColor = [UIColor darkGrayColor];
contentText.textColor = [UIColor darkGrayColor];
}
else {
}
}
----------------------------------------------------------------------------------------------------------
C. 開啟 ArticleListViewController.m 檔案, 修改如下:
//@add
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
ArticleViewController *articleViewController = [[ArticleViewController alloc] init];
NSManagedObject *article = [[self fetchedResultsController] objectAtIndexPath:indexPath];
//articleViewController.title = [NSString stringWithFormat:@"%@",[article valueForKey:@"title"]];
articleViewController.article = article;
[self.navigationController pushViewController:articleViewController animated:YES];
[articleViewController release];
}
----------------------------------------------------------------------------------------------------------
D. 開啟 ArticleViewController.xib 檔案設計 UI 如下:
1. 新增四個 Label, 一個 TextView(取消編輯功能)
2. 將 File's Owner 的 titleLabel, subTitleLabel 與 contentText 分別連結至
對應的二個 Label 與 TextView
2. 將 File's Owner 的 titleLabel, subTitleLabel 與 contentText 分別連結至
對應的二個 Label 與 TextView
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。