Ios 将数据从UITableViewController推送到UIViewController
在将数据从我的Ios 将数据从UITableViewController推送到UIViewController,ios,iphone,objective-c,uitableview,uiviewcontroller,Ios,Iphone,Objective C,Uitableview,Uiviewcontroller,在将数据从我的UITableView推送到我的UIViewController上的5个标签时,我遇到了一个相当大的问题。我有一个应用程序,你可以按“爬升”,根据你选择的爬升,当你被推到UIViewController时,会显示不同的规格。现在它只是进入了一个空白屏幕,我把我的标签连接到我的课堂上,所有这些都只是不确定如何让tit将不同的信息传输到每个标签上,这取决于选择的攀登。我现在将发布我的代码: FourthTableViewController.h: #import <UIKit/U
UITableView
推送到我的UIViewController
上的5个标签时,我遇到了一个相当大的问题。我有一个应用程序,你可以按“爬升”,根据你选择的爬升,当你被推到UIViewController
时,会显示不同的规格。现在它只是进入了一个空白屏幕,我把我的标签连接到我的课堂上,所有这些都只是不确定如何让tit将不同的信息传输到每个标签上,这取决于选择的攀登。我现在将发布我的代码:
FourthTableViewController.h
:
#import <UIKit/UIKit.h>
@interface FourthTableViewController : UITableViewController
@property (nonatomic, strong) NSString *sectionName;
@property (nonatomic, strong) NSMutableArray *objects;
@property (nonatomic, strong) NSMutableArray *results;
@property (nonatomic, strong) IBOutlet UISearchBar *searchBar;
@end
#import "FourthTableViewController.h"
#import "DetailViewController.h"
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *NewBackButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:nil];
[[self navigationItem] setBackBarButtonItem:NewBackButton];
self.tableView.separatorColor = [UIColor colorWithRed:183/255.0 green:207/255.0 blue:85/255.0 alpha:0.5];
//populating arrays
NSDictionary *dict = @{/*Moss Rock Sections*/@"Grass Man":@[@"Tesseract", @"Chalky Dreams",
@"Aristocratic Nose", @"Bee Stings", @"Recovery Run Traverse", @"Heel Shock", @"Fourth of July",
@"No Sack", @"Poop Dreams", @"Hoop Dreams", @"Grass Man Traverse", @"Mikey Likes It", @"Just
Throw", @"Rapture", @"Caveman Hunt", @"Batman Dyno", @"Waiting Line", @"Petrified Lady
(project)", @"Up and Over", @"Rocker", @"Heart", @"Left Ventricle", @"Poison Ivey", @"Snake
Eyes", @"Rattle", @"Shape Shifter", @"Road to Nowhere", @"Beef It", @"Switchback", @"Pine
Phriend", @"Hanging Out", @"Warp Hole", @"Deet", @"Mosquito Bites"], @"Lost Roof": @[@"I'll
Tumble for Ya", @"Snoopy's House", @"Treelee", @"Lost Roof Problem"], @"Ozzy":@[@"Clark Direct",
@"Long Shot", @"Pile", @"Revolver", @"The Bomb", @"Suntoucher", @"A Young One",
@"Nebuchadnezzar's Dream", @"Profanity", @"Godfather", @"Re-Ignition", @"Rancid", @"Tree
Problem", @"Scrutinzier", @"Little Big Horn", @"Cheese is Good", @"Maybe Later", @"Double
Clutch", @"A.X Variation", @"Salute", @"Ozzy Crack", @"Adam's Slab", @"Orange Streak", @"Tommy
H", @"Vast Understatement", @"Super Crimp", @"Big Ben", @"Fat Cut", @"It Burns!", @"The Trip",
@"Tesseract"]/*End Moss Rock Sections*/, @"Colorado Section 1":@[@"Colorado Climb 1", @"Colorado
Climb 2", @"Colorado Climb 3"]};
climbs = dict[self.sectionName];
[self.objects addObjectsFromArray:climbs];
}
#import <UIKit/UIKit.h>
@interface DetailViewController : UIViewController
@property (strong, nonatomic) NSString *detailLabelContents;
@property (weak, nonatomic) IBOutlet UILabel *detailLabel;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *gradeLabel;
@property (weak, nonatomic) IBOutlet UILabel *coordinatesLabel;
@property (weak, nonatomic) IBOutlet UILabel *rockLabel;
@property (weak, nonatomic) IBOutlet UILabel *difficultyLabel;
@property (nonatomic, strong) NSString *climbName;
@end
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *NewBackButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:nil];
[[self navigationItem] setBackBarButtonItem:NewBackButton];
//populating arrays
NSDictionary *dict = @{@"Alabama Climb 1":@[@"Alabama Spec 1", @"Alabama Spec 2", @"Alabama Spec
3"], @"Georgia Climb 1": @[@"Georgia Spec 1", @"Georgia Spec 2", @"Georgia Spec 3"], @"Tennessee
Climb 1":@[@"Tennessee Spec 1", @"Tennessee Spec 2", @"Tennessee Spec 3"], @"Colorado Climb
1":@[@"Colorado Spec 1", @"Colorado Spec 2", @"Colorado Spec 3"]};
specs = dict[self.climbName];
self.detailLabel.text = self.detailLabelContents;
}
详细视图控制器.h
:
#import <UIKit/UIKit.h>
@interface FourthTableViewController : UITableViewController
@property (nonatomic, strong) NSString *sectionName;
@property (nonatomic, strong) NSMutableArray *objects;
@property (nonatomic, strong) NSMutableArray *results;
@property (nonatomic, strong) IBOutlet UISearchBar *searchBar;
@end
#import "FourthTableViewController.h"
#import "DetailViewController.h"
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *NewBackButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:nil];
[[self navigationItem] setBackBarButtonItem:NewBackButton];
self.tableView.separatorColor = [UIColor colorWithRed:183/255.0 green:207/255.0 blue:85/255.0 alpha:0.5];
//populating arrays
NSDictionary *dict = @{/*Moss Rock Sections*/@"Grass Man":@[@"Tesseract", @"Chalky Dreams",
@"Aristocratic Nose", @"Bee Stings", @"Recovery Run Traverse", @"Heel Shock", @"Fourth of July",
@"No Sack", @"Poop Dreams", @"Hoop Dreams", @"Grass Man Traverse", @"Mikey Likes It", @"Just
Throw", @"Rapture", @"Caveman Hunt", @"Batman Dyno", @"Waiting Line", @"Petrified Lady
(project)", @"Up and Over", @"Rocker", @"Heart", @"Left Ventricle", @"Poison Ivey", @"Snake
Eyes", @"Rattle", @"Shape Shifter", @"Road to Nowhere", @"Beef It", @"Switchback", @"Pine
Phriend", @"Hanging Out", @"Warp Hole", @"Deet", @"Mosquito Bites"], @"Lost Roof": @[@"I'll
Tumble for Ya", @"Snoopy's House", @"Treelee", @"Lost Roof Problem"], @"Ozzy":@[@"Clark Direct",
@"Long Shot", @"Pile", @"Revolver", @"The Bomb", @"Suntoucher", @"A Young One",
@"Nebuchadnezzar's Dream", @"Profanity", @"Godfather", @"Re-Ignition", @"Rancid", @"Tree
Problem", @"Scrutinzier", @"Little Big Horn", @"Cheese is Good", @"Maybe Later", @"Double
Clutch", @"A.X Variation", @"Salute", @"Ozzy Crack", @"Adam's Slab", @"Orange Streak", @"Tommy
H", @"Vast Understatement", @"Super Crimp", @"Big Ben", @"Fat Cut", @"It Burns!", @"The Trip",
@"Tesseract"]/*End Moss Rock Sections*/, @"Colorado Section 1":@[@"Colorado Climb 1", @"Colorado
Climb 2", @"Colorado Climb 3"]};
climbs = dict[self.sectionName];
[self.objects addObjectsFromArray:climbs];
}
#import <UIKit/UIKit.h>
@interface DetailViewController : UIViewController
@property (strong, nonatomic) NSString *detailLabelContents;
@property (weak, nonatomic) IBOutlet UILabel *detailLabel;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *gradeLabel;
@property (weak, nonatomic) IBOutlet UILabel *coordinatesLabel;
@property (weak, nonatomic) IBOutlet UILabel *rockLabel;
@property (weak, nonatomic) IBOutlet UILabel *difficultyLabel;
@property (nonatomic, strong) NSString *climbName;
@end
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *NewBackButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:nil];
[[self navigationItem] setBackBarButtonItem:NewBackButton];
//populating arrays
NSDictionary *dict = @{@"Alabama Climb 1":@[@"Alabama Spec 1", @"Alabama Spec 2", @"Alabama Spec
3"], @"Georgia Climb 1": @[@"Georgia Spec 1", @"Georgia Spec 2", @"Georgia Spec 3"], @"Tennessee
Climb 1":@[@"Tennessee Spec 1", @"Tennessee Spec 2", @"Tennessee Spec 3"], @"Colorado Climb
1":@[@"Colorado Spec 1", @"Colorado Spec 2", @"Colorado Spec 3"]};
specs = dict[self.climbName];
self.detailLabel.text = self.detailLabelContents;
}
总之,我想知道当选择攀爬时,攀爬规格显示在推送到的UIViewController
上的5个标签中,当选择另一个攀爬时,攀爬规格显示。(我认为这将是一个巨大的if/else声明)
任何建议或建设性的批评都将不胜感激,我知道我的语法并不完美,我对这门语言非常陌生
谢谢。要设置标签文本,您必须将
NSString
传递给下一个视图控制器
,然后在视图加载
中进行设置
因此,创建5个与标签对应的属性,并像使用grampname
NSString
(在prepareforsgue
方法中)一样传递数据
要设置标签文本,请在目标视图控制器的视图加载中执行此操作
self.titleLabel.text = self.myStringThatIPassed;
你是否在任何地方设置标签文本?我没有,这是我的问题,我不确定如何实现我的目标以及在何处实现目标?对,那么我是否会在DVC的“viewDidLoad”中做一个巨大的if-else语句,说明当选择此爬升时,将标签设置为此文本?对不起,我只是不能理解这个概念,你能给我看一个例子和我提供的代码吗?然后我可以看着它,更好地理解和想象它。一次攀爬如何将5个标签设置为特定的文本不是真的,你决定在你的PrepareForegue中传递什么数据或字符串。当然,给我一点时间。你能告诉我你从哪里得到标题、难度等等吗?