У меня есть 11 uilabels как список.я пытаюсь загрузить первые значения массива itemModel и нажать на следующую кнопку, он должен загрузить следующий набор значений массива itemModel в uilabels.
[ItemsModel(Material: "RMECC_MOB1", Qty: "2.000", UoM: "KG",
totalValue: "1000.000", Requistor: "", StorageLocation: "3001",
MatGrp: "00107", valuationPrice: "1000.000", ItemCategory: "0",
lineNo: "00010", UnitofPrice: “1.000"),
ItemsModel(Material: "RMECC_MOB1", Qty: "2.000", UoM: "KG",
totalValue: "1000.000", Requistor: "", StorageLocation: "3001",
MatGrp: "00107", valuationPrice: "1000.000", ItemCategory: "0",
lineNo: "00020", UnitofPrice: “1.000")]
Как загрузить значения itemModel в 11 uilabels, а затем как загрузить массивследующего значения itemModel в uilabels при нажатии следующей кнопки?
Использование TableView:
В этой функции получение ответа json и добавление в модель массива.
func GetPoItemCount() {
if orderNo != nil {
// Call API
print("orderni::\(orderNo!)")
self.PoItemsArray1.removeAll()
PoVendorListApiManager.sharedInstance.getPoListWithModel(orderString: orderNo!){ (json:JSON) in
// return json from API
if let results = json["d"]["results"].array {
for category in results {
self.PoItemsArray1.append(poItemsModel(json: category))
}
print("self.PoItemsArray array:::\(self.PoItemsArray1)")
DispatchQueue.main.async { // back to the main que and reload table
self.tableView.reloadData()
}
}
}
}
}
Сохранение результата jsonзначение в массив модели и массив выглядит следующим образом:
[ItemsModel(Material: "RMECC_MOB1", Qty: "2.000", UoM: "KG",
totalValue: "1000.000", Requistor: "", StorageLocation: "3001",
MatGrp: "00107", valuationPrice: "1000.000", ItemCategory: "0",
lineNo: "00010", UnitofPrice: “1.000"),
ItemsModel(Material: "RMECC_MOB1", Qty: "2.000", UoM: "KG",
totalValue: "1000.000", Requistor: "", StorageLocation: "3001",
MatGrp: "00107", valuationPrice: "1000.000", ItemCategory: "0",
lineNo: "00020", UnitofPrice: “1.000")]
таблица данных:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
print("count::itemArray::\(self.PoItemsArray1)")
return self.PoItemsArray1.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! PoItemTableViewCell
let items = self.PoItemsArray1[indexPath.row]
return cell
}
Objective-c:
#import "ItemDetailsController.h"
#import "ItemDetailsTableCell.h"
#import "UtilityController.h"
@interface ItemDetailsController (){
IBOutlet UILabel *headerLabel;
IBOutlet UIButton *upButton;
IBOutlet UIButton *downButton;
IBOutlet UILabel *lineTitleLabel;
IBOutlet UILabel *lineLabel;
UtilityController *util;
NSMutableArray *titleArray;
NSMutableArray *valueArray;
IBOutlet UITableView *detailTable;
}
@end
@implementation ItemDetailsController
@synthesize
headerDetailDict, itemDetailDict, currency, checkTryout, itemDetailArray, serialNo, itemStatus;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
#pragma mark - IBAction
- (IBAction)backButton:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)upDownButton:(id)sender {
UIButton * btn = sender;
if (btn.tag<1) {
serialNo=serialNo-1;
}
else{
serialNo=serialNo+1;
}
[self upDownFunction];
}
#pragma mark - End
#pragma mark - Private Method
-(void)changeFontNameAndFontSize{
float headerLabelFontSize;
float lineTitleLabelFontSize;
float lineLabelFontSize;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
headerLabelFontSize=18.f;
lineTitleLabelFontSize=18.0;
lineLabelFontSize=18.0;
}else{
headerLabelFontSize=18.0;
lineTitleLabelFontSize=18.0;
lineLabelFontSize=18.0;
}
headerLabel.font=[UIFont fontWithName:@"Roboto-Regular" size:headerLabelFontSize];
headerLabel.textColor=[util colorWithHexString:@"ffffff"];
lineTitleLabel.font=[UIFont fontWithName:@"Roboto-Regular" size:lineTitleLabelFontSize];
lineTitleLabel.textColor=[UIColor whiteColor];
lineLabel.font=[UIFont fontWithName:@"Roboto-Regular" size:lineLabelFontSize];
lineLabel.textColor=[UIColor whiteColor];
}
-(void)upDownFunction{
if (itemDetailArray.count<=1) {
upButton.enabled=false;
downButton.enabled=false;
}
else{
if (serialNo==0) {
upButton.enabled=false;
downButton.enabled=true;
}
else if (serialNo ==itemDetailArray.count-1){
upButton.enabled=true;
downButton.enabled=false;
}
else{
upButton.enabled=true;
downButton.enabled=true;
}
}
if ([itemStatus isEqualToString:@"PO"]) {
headerLabel.text=@"PO Item Details";
itemDetailDict=[itemDetailArray objectAtIndex:serialNo];
NSString *line=[NSString stringWithFormat:@"(%@)",[util trimLeadingZero:[itemDetailDict objectForKey:@"line_no"]]];
lineLabel.text=line;
NSString *materialNo=[itemDetailDict objectForKey:@"material_no"];
NSString *description=[itemDetailDict objectForKey:@"description"];
NSString *fixedVendorNo=[itemDetailDict objectForKey:@"vendor"];
NSString *vendorName=[itemDetailDict objectForKey:@"vendor_name"];
NSString *purchOrg=[itemDetailDict objectForKey:@"purchase_org"];
NSString *purchGroup=[itemDetailDict objectForKey:@"purchasing_group"];
NSString *qty=[itemDetailDict objectForKey:@"po_qty"];
NSString *uom=[itemDetailDict objectForKey:@"uom"];
NSString *qtyUom=[qty stringByAppendingFormat:@" %@",uom];
NSString *netPrice=[itemDetailDict objectForKey:@"net_price"];
NSString *Currency=[itemDetailDict objectForKey:@"currency"];
NSString *netPriceString=[util currencyFormat:[netPrice floatValue] currency:Currency];
NSString *totalValue=[itemDetailDict objectForKey:@"total_value"];
NSString *totalValueString=[util currencyFormat:[totalValue floatValue] currency:Currency];
NSString *deliveryDate=[itemDetailDict objectForKey:@"delvry_date"];
NSString *timeStampString=[util getTimeStamp:deliveryDate];
NSString *dateString= timeStampString;
NSString *matGroup=[itemDetailDict objectForKey:@"material_group"];
NSString *plant=[itemDetailDict objectForKey:@"plant"];
NSString *storageLocation=[itemDetailDict objectForKey:@"storage_loc"];
NSString *reqTrack=[itemDetailDict objectForKey:@"req_tracking_number"];
NSString *AAC=[itemDetailDict objectForKey:@"acct_assgn_category_desc"];
NSString *itemCategory=[itemDetailDict objectForKey:@"item_category"];
NSString *glAccount=[itemDetailDict objectForKey:@"gl_acct_number"];
NSString *costCenter=[itemDetailDict objectForKey:@"cost_center"];
NSString *order=[itemDetailDict objectForKey:@"order_number"];
NSString *WBS=[itemDetailDict objectForKey:@"wbs"];
NSString *pofitCenter=[itemDetailDict objectForKey:@"profit_center"];
titleArray=[[NSMutableArray alloc] initWithObjects:@"Material #",@"Description",@"Vendor #",@"Vendor Name",@"Purch Org",@"Purch Group",@"Qty | UoM",@"Net Price",@"Total Value",@"Delivery Date",@"Mat Grp",@"Plant",@"Storage Location",@"Req Track #",@"AAC",@"Item Category",@"G/L Account",@"Cost Center",@"Order",@"WBS",@"Profit Center", nil];
valueArray=[[NSMutableArray alloc] initWithObjects:materialNo,description,fixedVendorNo,vendorName,purchOrg,purchGroup,qtyUom,netPriceString,totalValueString,dateString,matGroup,plant,storageLocation,reqTrack,AAC,itemCategory,glAccount,costCenter,order,WBS,pofitCenter, nil];
}
else if ([itemStatus isEqualToString:@"PR"]){
headerLabel.text=@"PR Item Details";
itemDetailDict=[itemDetailArray objectAtIndex:serialNo];
NSLog(@"pr itemDetailDict %@",itemDetailDict);
//NSString *line=[NSString stringWithFormat:@"(%@)",[util trimLeadingZero:[itemDetailDict objectForKey:@"line_no"]]];
NSString *line=[NSString stringWithFormat:@"(%@)",[util trimLeadingZero:[itemDetailDict objectForKey:@"line_no"]]];
//[util trimLeadingZero:[itemDetailDict objectForKey:@"line_no"]];
lineLabel.text=line;
NSString *materialNo=[itemDetailDict objectForKey:@"material_no"];
NSString *description=[itemDetailDict objectForKey:@"description"];
NSString *fixedVendorNo=[itemDetailDict objectForKey:@"fixed_vendor"];
NSString *vendorName=[itemDetailDict objectForKey:@"fixed_vendor_name"];
NSString *purchOrg=[itemDetailDict objectForKey:@"purchase_org"];
NSString *purchGroup=[itemDetailDict objectForKey:@"purchasing_group"];
NSString *qty=[itemDetailDict objectForKey:@"pr_qty"];
NSString *uom=[itemDetailDict objectForKey:@"uom"];
NSString *qtyUom=[qty stringByAppendingFormat:@" %@",uom];
NSString *valuationPrice=[itemDetailDict objectForKey:@"net_price"];
NSString *Currency=[itemDetailDict objectForKey:@"currency"];
NSString *valuationPriceString=[util currencyFormat:[valuationPrice floatValue] currency:Currency];
NSString *totalValue=[itemDetailDict objectForKey:@"total_value"];
NSString *totalValueString=[util currencyFormat:[totalValue floatValue] currency:Currency];
NSString *deliveryDate=[itemDetailDict objectForKey:@"delvry_date"];
NSString *timeStampString=[util getTimeStamp:deliveryDate];
NSString *dateString= timeStampString;
NSString *matGroup=[itemDetailDict objectForKey:@"material_group"];
NSString *plant=[itemDetailDict objectForKey:@"plant"];
NSString *storageLocation=[itemDetailDict objectForKey:@"storage_loc"];
NSString *reqTrack=[itemDetailDict objectForKey:@"req_tracking_number"];
NSString *AAC=[itemDetailDict objectForKey:@"acct_assgn_category_desc"];
NSString *itemCategory=[itemDetailDict objectForKey:@"item_category"];
NSString *glAccount=[itemDetailDict objectForKey:@"gl_acct_number"];
NSString *costCenter=[itemDetailDict objectForKey:@"cost_center"];
NSString *order=[itemDetailDict objectForKey:@"order_number"];
NSString *WBS=[itemDetailDict objectForKey:@"wbs"];
NSString *pofitCenter=[itemDetailDict objectForKey:@"profit_center"];
titleArray=[[NSMutableArray alloc] initWithObjects:@"Material #",@"Description",@"Fixed Vendor #",@"Vendor Name",@"Purch Org",@"Purch Group",@"Qty | UoM",@"Valuation Price",@"Total Value",@"Delivery Date",@"Mat Grp",@"Plant",@"Storage Location",@"Req Track #",@"AAC",@"Item Category",@"G/L Account",@"Cost Center",@"Order",@"WBS",@"Profit Center", nil];
valueArray=[[NSMutableArray alloc] initWithObjects:materialNo,description,fixedVendorNo,vendorName,purchOrg,purchGroup,qtyUom,valuationPriceString,totalValueString,dateString,matGroup,plant,storageLocation,reqTrack,AAC,itemCategory,glAccount,costCenter,order,WBS,pofitCenter, nil];
}
[detailTable reloadData];
}
#pragma mark - End
#pragma mark - ViewLifeCycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(@"serialNo %d",serialNo);
util=[[UtilityController alloc]init];
[self changeFontNameAndFontSize];
[self upDownFunction];
}
#pragma mark - End
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return titleArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"ItemDetailsTableCell";
ItemDetailsTableCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[ItemDetailsTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
float titleLabelFontSize;
float valueLabelFontSize;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
titleLabelFontSize=20.0;
valueLabelFontSize=20.0;
}else{
titleLabelFontSize=12.0;
valueLabelFontSize=14.0;
}
cell.titleLabel.font =[UIFont fontWithName:@"Roboto-Condensed" size:titleLabelFontSize];
cell.titleLabel.textColor=[util colorWithHexString:@"252525"];
cell.valueLabel.font=[UIFont fontWithName:@"Roboto-Condensed" size:titleLabelFontSize];
cell.valueLabel.textColor=[util colorWithHexString:@"252525"];
cell.titleLabel.text=[titleArray objectAtIndex:indexPath.row];
cell.valueLabel.text=[valueArray objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath{
}
#pragma mark- End
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Любая помощь высоко ценится пожалуйста ...