初学者-我有一个TableViewController,可以在DetailView中打印一个故事。
我已经在我的DetailView选项卡栏中成功实现了“上一个”和“下一个”按钮,在点击该按钮时,在第1行或第+1行当前的indexRow值上打印故事。我已将“最后一个”按钮设置为在第一行消失,而将“下一个”按钮设置为在最后一行消失。
但是,当我进入DetailView并导航“下一个”和“最后一个”并到达最后一行或第一行时,“最后一个”或“下一个”分别消失,并且它们不再返回。我怀疑这是由于我如何构造if语句,并且需要一些帮助来解决此问题。有人可以告诉我错误吗?
我遇到的另一个相关问题是,如果您在TableView中选择第一行或最后一行,则DetailView会加载Last或Next,并且只有当我离开第一个或最后一个故事并返回到第二个故事时,这些才会消失第一个或最后一个故事。解决此问题的最佳方法是什么?
到目前为止,这是我的代码。
<?php
include 'includes/session.php';
$qr_code = $_POST['inputQr'];
$conn = $pdo->open();
$checkQr = $conn->prepare("SELECT *, COUNT(*) AS checkrows FROM product WHERE qr_code=:qr_code");
$checkQr->execute(['qr_code'=>$qr_code]);
$qr = $checkQr->fetch();
$response = array('status'=>'success','message'=>'Barcode exists'); // be positive here
if($qr['checkrows'] <= 0){
$msg = 'Barcode doesn\'t exist! Kindly review your input!';
$_SESSION['error'] = $msg;
$response = array('status'=>'error','message'=>$msg);
}
$pdo->close();
echo json_encode($response);
?>
答案 0 :(得分:1)
最好更改用户交互方式,而不要更改标题
@IBAction func lastButton(_ sender: Any) {
if ((self.selectedIndex - 1) < self.stories.count) {
self.selectedIndex = self.selectedIndex - 1
let nextStory = self.stories[self.selectedIndex]
DispatchQueue.global().async {
let nextStoryText = try? String(contentsOf: nextStory)
DispatchQueue.main.async {
self.textView.text = nextStoryText
}
}
let storyTitle = nextStory.deletingPathExtension().lastPathComponent
storyTitleLabel.title = storyTitle
}
changeTheBarButtonUserInteraction()
}
@IBAction func nextButton(_ sender: Any) {
if ((self.selectedIndex + 1) < self.stories.count) {
self.selectedIndex = self.selectedIndex + 1
let nextStory = self.stories[self.selectedIndex]
DispatchQueue.global().async {
let nextStoryText = try? String(contentsOf: nextStory)
DispatchQueue.main.async {
self.textView.text = nextStoryText
}
}
let storyTitle = nextStory.deletingPathExtension().lastPathComponent
storyTitleLabel.title = storyTitle
}
changeTheBarButtonUserInteraction()
}
func changeTheBarButtonUserInteraction(){
lastLabel.isEnabled = selectedIndex != 0 ? true : false
nextLabel.isEnabled = ((self.selectedIndex + 1) == self.stories.count) ? false : true
}
答案 1 :(得分:0)
@IBAction func lastButton(_ sender: Any) { if ((self.selectedIndex - 1) < self.stories.count) { self.selectedIndex = self.selectedIndex - 1 let nextStory = self.stories[self.selectedIndex] DispatchQueue.global().async { let nextStoryText = try? String(contentsOf: nextStory) DispatchQueue.main.async { self.textView.text = nextStoryText } } let storyTitle = nextStory.deletingPathExtension().lastPathComponent storyTitleLabel.title = storyTitle } if selectedIndex == 0 { lastLabel.title = "" } else { lastLabel.title = "Last" } nextLabel.title = "Next"}
@IBAction func nextButton(_ sender: Any) { if ((self.selectedIndex + 1) < self.stories.count) { self.selectedIndex = self.selectedIndex + 1 let nextStory = self.stories[self.selectedIndex] DispatchQueue.global().async { let nextStoryText = try? String(contentsOf: nextStory) DispatchQueue.main.async { self.textView.text = nextStoryText } } let storyTitle = nextStory.deletingPathExtension().lastPathComponent storyTitleLabel.title = storyTitle } if ((self.selectedIndex + 1) == self.stories.count) { nextLabel.title = "" } else { nextLabel.title = "Next" }lastLabel.title = "Last"} }
但是,如果您隐藏并显示按钮会更好,因为如果按钮具有宽度,则用户仍然可以按下按钮。
如果您仍然遇到困难,请告诉我。