在簡單的TableViewController項目中出現錯誤,因爲它看起來像我試圖強制對象作爲cellForRowAtIndexPath
方法的一部分,被稱爲CheckValue.text
的標籤的文本。[NSDecimalNumber Length]:發送到實例的無法識別的選擇器
事實上,我正在努力做到這一點,因爲我需要將NSDecimalNumber
的值顯示在TableCell上。任何人都可以幫忙,因爲我覺得我在這裏接近子彈嗎?
下面是從TableViewController.m代碼
#import "TableViewController.h"
#import "TableCell.h"
@interface TableViewController()
{
NSMutableData *webData;
NSURLConnection *connection;
NSMutableArray *array;
}
@end
@implementation TableViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
// Get an array from web and Populate Check Arrays with New Data as above ...
[self GetDatabaseData];
}
-(void)GetDatabaseData{
NSURL *blogURL = [NSURL URLWithString:JSON_URL];
NSData *jsonData = [NSData dataWithContentsOfURL:blogURL];
NSError *error = nil;
//NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData: jsonData options:0 error:&error];
NSArray *TransactionArray = [NSJSONSerialization JSONObjectWithData: jsonData options:0 error:&error];
NSDecimalNumber *check_total = [NSDecimalNumber zero];
NSString *current_check;
// Loop through Json objects, create question objects and add them to our questions array
for (int i = 0; i < TransactionArray.count; i++)
{
NSDictionary *jsonElement = TransactionArray[i];
// Accumulate if this is part of the same check.
NSDecimalNumber *line_total = [NSDecimalNumber decimalNumberWithString:jsonElement[@"tran_value"]];
// Decide if this is Element Belong to the Last Check number.
if (jsonElement[@"tran_check"] == current_check){
check_total = line_total; // Reset Check Total to be the Value of this Line on NEW Checks
}
else{
check_total = [check_total decimalNumberByAdding:line_total]; //Add this Line Value to the Running Check Total
}
current_check = jsonElement[@"tran_check"]; // Make this Check number the Current Check for Totalizing.
_Checknumbers = @[jsonElement[@"tran_check"]];
_CheckTime = @[jsonElement[@"tran_hour"]];
_CheckValue = @[check_total];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _Checknumbers.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
static NSString *CellIdentifier = @"TableCell";
TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
int row = [indexPath row];
cell.CheckLabel.text = _Checknumbers[row];
cell.CheckValue.text = _CheckValue[row];
cell.CheckTime.text = _CheckTime[row];
return cell;
}
@end
的[我如何調試「無法識別的選擇發送到實例」錯誤]可能的複製(http://stackoverflow.com/questions/25853947/how-can-i-debug-unrecognized-選擇器發送到實例錯誤) –
嗨熱舔,我確實設法找到代碼行的問題,並知道必須做什麼,只是不知道這種轉換的語法。 – Rob4236