I use Xcode 6.2, and swift and this particular class with which I am having issue is in ObjectiveC. I am using storyboard, a tabcontroller, and one of the tabs calls the
historyViewController`,它有一个表视图。在iOS7中,当我单击历史记录tabBarton时,将显示表视图及其数据。
在iOS8中,当我点击历史记录tabBarButton时,表格视图不会出现。如果我单击其他tabBarButton,然后再次选择历史记录tabBarton,则表视图会正确显示其数据。
#import "historyListViewController.h"
#import "QRdatabase.h"
#import "qrdbinfo.h"
#import "historyDetailViewController.h"
#import <UIKit/UIKit.h>
#import "SDWebImage/UIImageView+WebCache.h"
#import "UIImageView+WebCache.h"
@implementation historyListViewController
@synthesize details = _details;
@synthesize qrInfos = _qrInfos;
@synthesize segmentchange;
- (IBAction)valid_in_seg:(id)sender
{
if (segmentchange.selectedSegmentIndex == 0)
{ self.qrInfos = [QRdatabase database].qrdbInfos;
[self.tablelist reloadData];
}
else
{
self.qrInfos = [QRdatabase database].inqrdbInfos;
}
[self.tablelist reloadData];
}
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
// Scroll table view to the last row
if (_shouldScrollToLastRow)
{
_shouldScrollToLastRow = NO;
[self.tablelist setContentOffset:CGPointMake(0, CGFLOAT_MAX)];
}
[self.tablelist reloadData];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self.tablelist reloadData];
UIImage *myImage =[UIImage imageNamed:@"logo_white_38.png"];
UIImageView *myImageView = [[UIImageView alloc] initWithImage:myImage];
[myImageView setFrame:CGRectMake(0, 0, 38, 38)];
self.navigationItem.titleView = myImageView;
self.navigationController.navigationBar.backgroundColor = [UIColor redColor];
segmentchange.tintColor = [UIColor redColor];
_shouldScrollToLastRow = YES;
if (segmentchange.selectedSegmentIndex == 0)
{
self.qrInfos = [QRdatabase database].qrdbInfos;
[self.tablelist reloadData];
}
else
{
self.qrInfos = [QRdatabase database].inqrdbInfos;
[self.tablelist reloadData];
}
self.tablelist.delegate = self;
self.tablelist.dataSource = self;
[self.view addSubview:self.tablelist];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if (segmentchange.selectedSegmentIndex == 0)
{
self.qrInfos = [QRdatabase database].qrdbInfos;
[self.tablelist reloadData];
}
else
{
self.qrInfos = [QRdatabase database].inqrdbInfos;
[self.tablelist reloadData];
}
[self.tablelist reloadData];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
[[NSURLCache sharedURLCache] removeAllCachedResponses];
}
/*- (void)viewDidUnload {
self.qrInfos = nil;
self.details = nil;
}*/
#pragma mark Table view methods
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{ if (segmentchange.selectedSegmentIndex == 0)
{
return 80;
}
else
return 120;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [_qrInfos count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (segmentchange.selectedSegmentIndex == 0)
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [self.tablelist dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];}
qrdbinfo *info = [_qrInfos objectAtIndex:indexPath.row];
cell.textLabel.text = info.qr_code;
cell.detailTextLabel.text = [NSString stringWithFormat:@"Date: %@", info.date];
CGSize itemSize = CGSizeMake(30, 30);
UIGraphicsBeginImageContext(itemSize);
CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[cell.imageView.image drawInRect:imageRect];
cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:info.img]
placeholderImage:[UIImage imageNamed:@"img_not_available.png"]];
return cell;
}
else
{
static NSString *CellIdentifier = @"Cell2";
UITableViewCell *cell = [self.tablelist dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
qrdbinfo *info = [_qrInfos objectAtIndex:indexPath.row];
cell.textLabel.text = info.qr_code;
cell.detailTextLabel.text = [NSString stringWithFormat:@"Date: %@", info.date];
return cell;
}
// return cell;
}
- (void)downloadImageWithURL:(NSURL *)url completionBlock:(void (^)(BOOL succeeded, UIImage *image))completionBlock
{
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if ( !error )
{
UIImage *image = [[UIImage alloc] initWithData:data];
completionBlock(YES,image);
} else{
completionBlock(NO,nil);
}
}];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(segmentchange.selectedSegmentIndex == 0)
{
qrdbinfo *info = [_qrInfos objectAtIndex:indexPath.row];
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"Main"
bundle:nil];
historyDetailViewController * vc = [sb instantiateViewControllerWithIdentifier:@"detail"];
vc.hidesBottomBarWhenPushed = YES;
vc.qrId = info.uniqueId;
[self.navigationController pushViewController:vc animated:YES];
}
else
{
UIAlertView *alerts = [[UIAlertView alloc] initWithTitle:@" Data Unavailable" message:@"No data available for invalid scans" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil, nil];
[alerts show];
}
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
qrdbinfo *info = [_qrInfos objectAtIndex:indexPath.row];
[self.qrInfos removeObjectAtIndex:indexPath.row];
[self.tablelist deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
if(segmentchange.selectedSegmentIndex == 0)
{
// Delete the row from the data source
[[QRdatabase database] deleterow:info.uniqueId];
}
else
{
[[QRdatabase database] deleteinvalidrow:info.uniqueId];
}
[self.tablelist reloadData ];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
@end