- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 UITableview,我用数据库中的数据填充了它,我知道将什么数据发送到另一个 View (detailViewController),但是我无法让它工作,现在我正在通过 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
方法。我有两个类 UITableview 类和它们在下面的详细信息类。我还有一个 NSObject 类,它保存数据库的对象。请检查一下,这是我的代码:
UITableView类代码:
Header File
#import <UIKit/UIKit.h>
#import <sqlite3.h>
@interface ExerciseViewController : UITableViewController {
NSMutableArray *theauthors;
sqlite3 * db;
}
@property(nonatomic,retain) NSMutableArray *theauthors;
-(NSMutableArray *) authorList;
@end
执行文件
#import "ExerciseViewController.h"
#import "sqlColumns.h"
#import <sqlite3.h>
#import "UIColor+FlatUI.h"
#import "ExerciseDetailViewController.h"
@interface ExerciseViewController ()
@end
@implementation ExerciseViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Abdominal";
[self authorList];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.theauthors count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"exerciseCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
sqlColumns *author = [self.theauthors objectAtIndex:indexPath.row];
UILabel *exerciseName = (UILabel *)[cell viewWithTag:101];
exerciseName.text = author.Name;
UILabel *equipment = (UILabel *)[cell viewWithTag:102];
equipment.text = author.Equipment;
NSString *string = author.Equipment;
NSString *trimmedString = [string stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
if ([trimmedString isEqualToString:@"null"]) {
equipment.text = @"No Equipment";
}
UILabel *difficulty = (UILabel *)[cell viewWithTag:103];
difficulty.text = author.Difficulty;
if ([difficulty.text isEqualToString:@"Easy"]) {
difficulty.textColor = [UIColor emerlandColor];
}
if ([difficulty.text isEqualToString:@"Intermediate"]) {
difficulty.textColor = [UIColor belizeHoleColor];
}
if ([difficulty.text isEqualToString:@"Hard"]) {
difficulty.textColor = [UIColor alizarinColor];
}
if ([difficulty.text isEqualToString:@"Very Hard"]) {
difficulty.textColor = [UIColor alizarinColor];
}
UIImageView *cellImageView = (UIImageView *)[cell viewWithTag:100];
cellImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",author.File]];
UIView *bgColorView = [[UIView alloc] init];
bgColorView.backgroundColor = [UIColor cloudsColor];
bgColorView.layer.masksToBounds = YES;
[cell setSelectedBackgroundView:bgColorView];
return cell;
}
-(NSMutableArray *) authorList{
_theauthors = [[NSMutableArray alloc] initWithCapacity:10];
@try {
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"StayhealthyExercises.sqlite"];
BOOL success = [fileMgr fileExistsAtPath:dbPath];
if(!success)
{
NSLog(@"Cannot locate database file '%@'.", dbPath);
}
if(!(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK))
{
NSLog(@"An error has occured: %s", sqlite3_errmsg(db));
}
const char *query = "SELECT * FROM strengthexercises WHERE primarymuscle LIKE '%abdominal%'";
const char *sql = query;
sqlite3_stmt *sqlStatement;
if(sqlite3_prepare(db, sql, -1, &sqlStatement, NULL) != SQLITE_OK)
{
NSLog(@"Problem with prepare statement: %s", sqlite3_errmsg(db));
}else{
while (sqlite3_step(sqlStatement)==SQLITE_ROW) {
sqlColumns * author = [[sqlColumns alloc] init];
author.Name = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,1)];
author.Muscle = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,2)];
author.Description = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 3)];
author.File= [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 4)];
author.Sets= [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 5)];
author.Reps= [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 6)];
author.Equipment= [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 7)];
author.PrimaryMuscle= [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 8)];
author.SecondaryMuscle= [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 9)];
author.Difficulty= [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 10)];
[_theauthors addObject:author];
}
}
sqlite3_finalize(sqlStatement);
}
@catch (NSException *exception) {
NSLog(@"Problem with prepare statement: %s", sqlite3_errmsg(db));
}
@finally {
sqlite3_close(db);
return _theauthors;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"detail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
sqlColumns *author = [self.theauthors objectAtIndex:indexPath.row];
ExerciseDetailViewController *destViewController = segue.destinationViewController;
destViewController.exerciseImage.image = [UIImage imageNamed:author.File];
destViewController.descriptionLabel.text = author.Description;
}
}
@end
现在是 DetailViewController
头文件:
#import <UIKit/UIKit.h>
#import "sqlColumns.h"
@interface ExerciseDetailViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIImageView *exerciseImage;
@property (weak, nonatomic) IBOutlet UILabel *descriptionLabel;
@property (nonatomic, strong) sqlColumns *author;
@end
执行文件
#import "ExerciseDetailViewController.h"
#import "ExerciseViewController.h"
@interface ExerciseDetailViewController ()
@end
@implementation ExerciseDetailViewController
@synthesize exerciseImage,descriptionLabel,author;
- (void)viewDidLoad
{
[super viewDidLoad];
descriptionLabel.text = author.Description;
NSLog(@"%@",author.Description);
}
@end
一定是一个小错误,任何帮助将不胜感激!
最佳答案
我认为问题在于您的网点为零。您只能在调用 viewDidLoad 后设置文本和图像。
尝试将您的信息保存在其他属性中,并在调用 viewDidLoad 后将此信息分配给您的标签和 ImageView 。
在你准备 segue 时:
destViewController.image = [UIImage imageNamed:author.File];
destViewController.text = author.Description;
在您的 header 中添加这些属性:
@property (strong, nonatomic) UIImage *image;
@property (strong, nonatomic) NSString *text;
然后在你的viewDidLoad中:
exerciseImage.image = self.image;
descriptionLabel.text = self.text;
关于ios - 将数据发送到 detailViewController 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20723376/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!