在我的应用程序中,我有一个要显示的新闻列表,我正在使用自定义tableview,其中包含标题,缩略图和更多按钮。点击更多按钮,将进入具有描述的详细视图。我已经解析了JSON响应以列出页面中的feed。但我对细节页面感到震惊。以下是我的代码:
.m文件
@interface NewsViewController ()
@property (nonatomic , retain) NSMutableArray *mArray;
@property (nonatomic , retain) NSDictionary *nDic;
@end
@implementation NewsViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"http://almithaq.mawaqaademo11.com/API.svc/getNews" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
self.nDic = (NSDictionary *)responseObject;
self.mArray = self.nDic[@"News"];
[self.mTab reloadData];
NSLog(@"response dateJSON: %@", self.mArray);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}
#pragma mark - TableConfiguration
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.mArray count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *Identifier = @"MyIdentifier";
NewsCell *cell12 = (NewsCell *)[tableView dequeueReusableCellWithIdentifier:Identifier];
if (cell12 == nil) {
NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"NewsCell" owner:self options:nil];
cell12 = [nib objectAtIndex:0];
}
cell12.newsDescription.text = [[self.mArray objectAtIndex:indexPath.row] objectForKey:@"Description"];
cell12.newsTitle.text = [[self.mArray objectAtIndex:indexPath.row] objectForKey:@"Title"];
cell12.newsThumbnail.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@",[[self.mArray objectAtIndex:indexPath.row] objectForKey:@"NewsImage"]]]]];
cell12.newsMore.tag = indexPath.row;
[cell12.newsMore addTarget:self action:@selector(NewsClicked:) forControlEvents:UIControlEventTouchUpInside];
return cell12;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 220;
}
-(void)backButtonClicked:(UIButton*)sender
{
if (sender.tag <= 25)
{
[self.navigationController popViewControllerAnimated:YES];
}
}
-(void)NewsClicked:(UIButton *)sender
{
if (sender.tag <= 25) {
NewsDetails *view1 = [[NewsDetails alloc]initWithNibName:@"NewsDetails" bundle:nil];
[self.navigationController pushViewController:view1 animated:YES];
}}
建议,提前谢谢。