我想使用Storyboard中的segue(ShowADVDetail)将数据从TableViewController单元格传递给DetailViewContoller(UITableViewController).
我有一个NSMutableArray'故事'包含一个解析的RSS提要.
我正在使用以下prepareForSegue,它传递单元格的'title'值:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"ShowADVDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
NSString *theTitle = [[stories objectAtIndex: storyIndex] objectForKey: @"title"];
[[segue destinationViewController] setDetailItem:theTitle];
}
}
Run Code Online (Sandbox Code Playgroud)
通过以下行,我可以传递特定单元格的"标题"值.
NSString *theTitle = [[stories objectAtIndex: storyIndex] objectForKey: @"title"];
Run Code Online (Sandbox Code Playgroud)
我也可以像这样访问"描述"值和"链接"值:
NSString *theDescription = [[stories objectAtIndex: storyIndex] objectForKey: @"description"];
NSString *theLink = [[stories objectAtIndex: storyIndex] objectForKey: @"link"];
Run Code Online (Sandbox Code Playgroud)
但是如何在我的segue中传递所有3个值?
到目前为止,我的didSelectRowAtIndexPath看起来像这样:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO]
[self performSegueWithIdentifier:@"ShowADVDetail" sender:self];
} …Run Code Online (Sandbox Code Playgroud) 我做一个自定义Segue的Storyboard,我有一个包含此代码的按钮:
[self performSegueWithIdentifier:@"line3" sender:sender];
Run Code Online (Sandbox Code Playgroud)
点击按钮就可以了.我遇到的问题是这个代码只能在一个不在void函数内部的按钮函数中运行.我试着点击按钮,效果很好.当我将其粘贴到void函数中时,它会给我一个抱怨发件人的错误.我尝试将其更改为无效,但没有任何反应.你能给我一些解决这个问题的见解吗?我正在检查a UserDefault并且它与我正在寻找的匹配然后我想要执行此代码:[self performSegueWithIdentifier:@"line3" sender:sender];
-(IBAction)LoginAttemp:(id)sender{
[self performSegueWithIdentifier:@"line3" sender:sender];
}
-(void) LoginFailed{
[self performSegueWithIdentifier:@"line3" sender:sender];
}
Run Code Online (Sandbox Code Playgroud)
错误我得到:
使用未声明的标识符'sender'
任何见解?
我尝试将详细信息披露按钮与故事板一起使用,但是当我从Disclosure Button构建一个segue到一个新视图时,它只能按下表格单元格,而不是按下详细信息披露按钮.
我必须做什么?
谢谢,
伯恩哈德
我的segue有一个奇怪的问题,这导致我的应用程序崩溃.该应用程序在第33行的ListViewController.m中崩溃:
dvc.menu = [self.blogPosts objectAtIndex:[[self.tableView indexPathForSelectedRow] row]];
出现以下错误:
menu[15782:c07] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<DetailViewController 0x7576d50> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key textView.'*
我现在已经研究了很长时间,似乎许多人遇到了同样的问题,尽管他们的解决方案似乎对我不起作用.这对我来说是一个全新的世界,我真的很想知道,我究竟做错了什么.
我已经上传了XCode项目供您查看,如果有任何帮助的话.在此处下载项目文件
提前致谢!
Xamarin.IOS/Monotouch中的以下情况适用:
我的问题
当我从VCOne类中的按钮单击事件处理程序执行以下调用时:
this.performSegue("OneToTwoSegue", this);
Run Code Online (Sandbox Code Playgroud)
我收到一个运行时错误,指出在MyVCOneClass对象上找不到OneToTwoSegue.
有谁知道为什么我不能从这样的代码中调用这个segue?我知道当我将它们链接到单元格,按钮等时,我看到segues正在工作......
是否有任何提示和技巧来解开unwind segues?
我遇到了麻烦,没有发生,或者" 无法识别的选择器发送到实例0x ?????? "错误.我也收到了警告" 警告:正在进行演示或解雇时尝试从视图控制器中解除警告!"
我有一个NSArray包含NSDictionary客户数据.我使用的NSPredicate过滤array,并使之通过ViewControllers用segues.我正处于一个阶段,我想改变存储在其中的键的一些值dictionary.这怎么可以实现?
我的prepareForSegue方法
if ([[segue identifier] isEqualToString:@"showClients"]) {
// Detect selected row
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
// Extract value from the Clinic_Location attribute
NSString *cString = [[_clinicList valueForKey:@"Clinic_Location"] objectAtIndex:indexPath.row];
NSLog(@"Row pressed: %@", cString);
// Set predicate where Clinic_Location equals the clinic string extracted from the selected row
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Clinic_Location == %@", cString];
// Filter the client array using this predicate
filteredClientArray …Run Code Online (Sandbox Code Playgroud) 我的ViewController中有一个tableView,该表的数据源来自另一个swift文件:DataSource.swift.这是数据源文件的代码:
import Foundation
import UIKit
class Datasource: NSData, UITableViewDataSource, UITableViewDelegate {
let itemsArray = ["Item 1","Item 2","Item 3","Item 4"]
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return itemsArray.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier:"test")
cell.textLabel!.text = self.itemsArray[indexPath.row]
return cell
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试添加此代码:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.performSegueWithIdentifier("mainToDetail", sender: self)
}
Run Code Online (Sandbox Code Playgroud)
但是它给了我一个错误,我也尝试了这个代码并且它也不起作用:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
ViewController.performSegueWithIdentifier("mainToDetail", sender: ViewController)
}
Run Code Online (Sandbox Code Playgroud)
我想添加一个功能,当我单击表中的一行时,会激活ViewController中的segue以显示DetailViewController.请帮忙!
当用户单击登录按钮时,我有一个登录到另一个场景的登录场景,但是,当我尝试在用户电子邮件和密码不正确时阻止它发生.我正在使用Firebase,下面的这个功能会检查用户名和密码是否正确,但我想在不正确时阻止发生这种情况.
func userLogin (user: String!, pass: String!){
ref.authUser(user, password: pass,
withCompletionBlock: { error, authData in
if error != nil {
print("user account doesnt exist")
} else {
print("You're logged in Fam")
}
})
}
Run Code Online (Sandbox Code Playgroud) 我想在单击表格单元格后从嵌入在导航控制器中的表格视图选择到另一个视图控制器。我仍然希望将第二个视图控制器嵌入到同一导航控制器中。因此,我通过情节提要创建了segue。
但是,我想在点击单元格后有条件地检查是否应该执行segue。
我已经签出了shouldPerformSegueWithIdentifier满足我需要的方法,但是不幸的是,它在表单击处理程序之前执行。如果我删除情节提要segue并仅通过进行segue performSegue,则我的第二个视图控制器不再嵌入相同的导航控制器中。
有什么建议吗?
这是我的代码:
// Called on click event on table cell
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let app = apps[indexPath.section]
if app.state == .INSTALLED {
let inputVC = self.navigationController?.viewControllers[1] as? InputVC
inputVC?.app = app
performSegue(withIdentifier: "showAccSync", sender: self)
} else {
// show alert
}
}
Run Code Online (Sandbox Code Playgroud) segue ×10
ios ×7
objective-c ×5
swift ×3
storyboard ×2
uitableview ×2
xcode ×2
datasource ×1
disclosure ×1
drilldown ×1
firebase ×1
mobile ×1
nsarray ×1
nsdictionary ×1
nspredicate ×1
uistoryboard ×1
xamarin.ios ×1