Not sure if the above is even my question as I am basically new to using objective-c and iOS and not sure if that's the right wording but anyway...
不确定上面是否甚至是我的问题,因为我基本上不熟悉使用objective-c和iOS而且不确定这是否是正确的措辞但无论如何......
Basically I have completed this tutorial https://www.youtube.com/watch?v=ITUI7fukRO8 for using a tableView with an array of data.
基本上我已经完成了本教程https://www.youtube.com/watch?v=ITUI7fukRO8,用于使用带有数据数组的tableView。
The substance of the program consists of a navcontroller, tableviewController and a viewController for the extra detail of the table data.
该程序的实质包括一个navcontroller,tableviewController和一个viewController,用于表数据的额外细节。
Currently I have a button (from another viewcontroller) that is linking to my tableView. How would I go about setting up and IF statement in regards to the button pressed (-as I need to link other buttons from other controllers) so that if a specific button is pressed, the array that is displayed in the tableView is different.
目前我有一个链接(从另一个viewcontroller)链接到我的tableView。我如何设置关于按下按钮的设置和IF语句( - 我需要链接来自其他控制器的其他按钮),这样如果按下特定按钮,则tableView中显示的数组是不同的。
I'm currently thinking of doing a bunch of if, then, else statements and just manually changing the detail of the arrays.
我正在考虑做一堆if,then,else语句,只是手动改变数组的细节。
Is this the way to go?? Or should I just set up another table view for each of my buttons.
这是要走的路?或者我应该为每个按钮设置另一个表视图。
I have a set of .h and .m for the tableCell, tableCellController, and the ViewController.
我有一组.h和.m用于tableCell,tableCellController和ViewController。
That probably didn't make a whole lot of sense but if you somewhat understand help would be appreciated. Cheers
这可能没有多大意义,但如果你有点理解帮助将不胜感激。干杯
Edit: As you can see my code is pretty 'all over the shop' at the moment. I haven't included the Cell View controllers as I don't think they have that much relevance with what I want to do at this stage.The buttonviewcontroller is just a normal UIViewController and both buttons are linked as 'Button1'class in the storyboard. They have been given tags 0 and 1 which I believe is in under the 'view' subheading in the storyboard. Please alert me if this is wrong and I am missing something really obvious but that was the only place I could find 'tag'. ARRRG Objective-c is frustrating when you don't the language at all./ Updated Code as 21/03.
编辑:你可以看到我的代码目前非常“遍布整个商店”。我没有包含Cell View控制器,因为我认为它们与我在这个阶段想要做的事情没那么相关.buttonviewcontroller只是一个普通的UIViewController,两个按钮在故事板中被链接为'Button1'class 。他们已经给出了标签0和1,我认为它们位于故事板中的“视图”子标题下。请提醒我,如果这是错误的,我错过了一些非常明显的东西,但那是我唯一能找到'标签'的地方。 ARRRG Objective-c在您根本不使用该语言时会感到沮丧./更新代码为21/03。
ButtonViewController.M (this is where the buttons are)
ButtonViewController.M(这是按钮所在的位置)
#import <UIKit/UIKit.h>
#import "tableViewController.h"
#import "TableCell.h"
@interface ButtonViewController : UIViewController
-(IBAction) button_Clicked:(id)sender;
@property (strong, nonatomic) IBOutlet UIButton *Button1;
@end
ButtonViewController.m
ButtonViewController.m
#import "ButtonViewController.h"
#import "tableViewController.h"
#import "TableCell.h"
@interface ButtonViewController ()
@end
@implementation ButtonViewController
-(IBAction) button_Clicked:(id)sender
{
//something here that is going wrong
tableViewController *tableVC = [[tableViewController alloc]initWithNibName:@"tableViewController" bundle:nil];
if(_Button1.tag==0)
{
tableVC.buttonSelected = 0;
}
else if(_Button1.tag==1)
{
tableVC.buttonSelected = 1;
}
[self.navigationController pushViewController:tableVC animated:YES];
[tableVC.tableView reloadData];
@end
tableViewController.h
tableViewController.h
#import <UIKit/UIKit.h>
@interface tableViewController : UITableViewController
@property (nonatomic, assign) int buttonSelected;
@property (nonatomic, strong) NSArray *Title;
//@property (nonatomic, strong) NSMutableArray *Title;
@property (nonatomic, strong) NSArray *Description;
//@property (nonatomic, strong) NSMutableArray *Description;
//Not sure if Mutable or normal array
@end
tableViewController.m
tableViewController.m
#import "tableViewController.h"
#import "TableCell.h"
#import "DetailViewController.h"
#import "ButtonViewController.h"
@interface tableViewController ()
@end
@implementation tableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
if(_buttonSelected == 0)
{
_Title = @[@"Hamstring Muscle Tear",@"Lower Back Pain"];
_Description = @[@"Blahahaha", @"blahahaha2",@"blalalala3"];
[self.tableView reloadData];
}
else if (_buttonSelected == 1)
{
_Title = @[@"1",@"2",@"3"];
_Description = @[@"dededdededde", @"deddedede2",@"blalalala3"];
[self.tableView reloadData];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return _Title.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"TableCell";
TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
int row = [indexPath row];
cell.TitleLabel.text = _Title[row];
cell.DescriptionLabel.text = _Description[row];
return cell;
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"ShowDetails"]) {
DetailViewController *detailviewcontroller = [segue destinationViewController];
NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow];
int row = [myIndexPath row];
detailviewcontroller.DetailModal = @[_Title[row],_Description[row]];
}
}
@end
1 个解决方案
#1
2
Do a CTRL - drag in Storyboard to create a IBAction for the button.
执行CTRL - 在Storyboard中拖动以创建按钮的IBAction。
In the IBAction method, get the data you want for your data arrays (Images, Title, Description ref the tutorial you linked). Then call:
在IBAction方法中,获取数据数组所需的数据(图像,标题,描述参考链接的教程)。然后打电话:
[tableview reloadData]
This will repopulate the tableview.
这将重新填充tableview。
#1
2
Do a CTRL - drag in Storyboard to create a IBAction for the button.
执行CTRL - 在Storyboard中拖动以创建按钮的IBAction。
In the IBAction method, get the data you want for your data arrays (Images, Title, Description ref the tutorial you linked). Then call:
在IBAction方法中,获取数据数组所需的数据(图像,标题,描述参考链接的教程)。然后打电话:
[tableview reloadData]
This will repopulate the tableview.
这将重新填充tableview。