Я получаю сообщение об ошибке при создании простого проекта TableViewController, поскольку он выглядит так, как будто я пытаюсь заставить объект NSDecimalNumber
в текст метки с именем CheckValue.text
как часть метода cellForRowAtIndexPath
,[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- selector-sent-to-instance-error) –
Hi Hot Licks, мне удалось найти проблему с линией кода и знал, что нужно делать, просто не знал синтаксиса для этого преобразования. – Rob4236