I am facing problem I am using Swift 3.0.1 for data save in core data some text and image I am facing this error in my code
AppDelegate.swift file
import UIKit
import CoreData
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
setUpAppearance()
return true
}
func setUpAppearance()
{
let navStyle = UINavigationBar .appearance()
navStyle.barTintColor = UIColor .orange
navStyle.tintColor = UIColor .darkGray
navStyle.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.darkGray]
}
table View File code
import UIKit
import CoreData
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
setUpAppearance()
return true
}
func setUpAppearance()
{
let navStyle = UINavigationBar .appearance()
navStyle.barTintColor = UIColor .orange
navStyle.tintColor = UIColor .darkGray
navStyle.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.darkGray]
}
any solution gives what I am doing......
Related
I have added a WKwebview in SwiftUI via UIVewRepresentable. I am having difficulties getting some buttons to make the web view go back and go forward. Below is the two classes I have made but I am not even getting print to work ( maybe a bug? ).
import SwiftUI
import WebKit
struct Webview : UIViewRepresentable {
let request: URLRequest
func makeUIView(context: Context) -> WKWebView {
return WKWebView()
}
func updateUIView(_ uiView: WKWebView, context: Context) {
uiView.load(request)
}
func goBack(){
// go back
print("go back")
}
func goForward (){
// go forward
print("go forward")
}
}
import SwiftUI
struct FullWebView : View {
let webview = Webview(request: URLRequest(url: URL(string: "https://www.apple.com")!))
var body: some View {
VStack{
HStack{
Button(action: {
//do something
self.webview.goBack()
}){
Text("back")
}
Spacer()
Button(action: {
//do something
self.webview.goForward()
}){
Text("forward")
}
}
webview
}
}
}
dfd thank you for pointing me on the correct path, your answer needed a little modification because adding the webview as a var to the struct means I needed to set a value on it when I use it, so I also had to add a custom init method. Anyway here is the code that works.
Webview struct
import SwiftUI
import WebKit
struct Webview : UIViewRepresentable {
let request: URLRequest
var webview: WKWebView?
init(web: WKWebView?, req: URLRequest) {
self.webview = WKWebView()
self.request = req
}
func makeUIView(context: Context) -> WKWebView {
return webview!
}
func updateUIView(_ uiView: WKWebView, context: Context) {
uiView.load(request)
}
func goBack(){
webview?.goBack()
}
func goForward(){
webview?.goForward()
}
}
and here is the struct using the webview and adding the buttons to the top
import SwiftUI
struct FullWebView : View {
let webview = Webview(web: nil, req: URLRequest(url: URL(string: "https://www.apple.com")!))
var body: some View {
VStack{
HStack{
Button(action: {
//do something
self.webview.goBack()
}){
Text("back")
}
Spacer()
Button(action: {
//do something
self.webview.goForward()
}){
Text("forward")
}
}
webview
}
}
}
When the user visits all three view controllers in no particular order. I want all of the view controllers in this program to turn green. But only if all three classes are visited. I don't know if this is a coredata or userdefulat thing.
import UIKit
class oneV: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
class twoV: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
class threeV: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
UserDefaults Will be great for this, saving a flag for each UIViewController in its viewDidLoad function.
Then adding up those three flags into one, and check it in viewWillAppear in each UIViewController.
Check this Code Below.
// First create this extension to check on each value
public extension UIViewController {
func isAllVistied() -> Bool {
let a = UserDefaults.standard.bool(forKey: "VC1") // Key used to save inside the viewController
let b = UserDefaults.standard.bool(forKey: "VC2")
let c = UserDefaults.standard.bool(forKey: "VC3")
if a && b && c {
return true
} else {
return false
}
}
}
Usage: In each UIViewController use this code:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
UserDefaults.standard.set(true, forKey: "VC1") //Key changes based on the current viewController used in example (VC1, VC2, VC3)
}
override func viewWillAppear(_ animated: Bool) {
if self.isAllVistied() {
view.backgroundColor = .green
}
}
}
Building my first app and hitting an error I can't figure out. I have a recycler view that shows a list of cards. I want to click the card and open another activity.
Here is my code:
import android.content.Context
import android.content.Intent
import android.support.v4.content.ContextCompat.startActivity
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import kotlinx.android.synthetic.main.list_tank_item.view.*
class TankAdapter(val context: Context, val tanks: List<Tank>) : RecyclerView.Adapter<TankAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, p1: Int): ViewHolder {
val view = LayoutInflater.from(context).inflate(R.layout.list_tank_item, parent, false)
return ViewHolder(view)
}
override fun getItemCount(): Int {
return tanks.size
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val tank = tanks[position]
holder.setData(tank, position)
}
inner class ViewHolder(itemview: View) : RecyclerView.ViewHolder(itemview) {
var currentTank: Tank? = null
var currentPosition: Int = 0
init {
itemView.setOnClickListener{
val intent = Intent(context, TankOverviewActivity::class.java)
var tank_id = currentTank._id.toString()
intent.putExtra("tank_id", tank_id)
startActivity(intent)
}
itemView.imgEdit.setOnClickListener{
Toast.makeText(context, currentTank!!.tank_name + " Edit button clicked!", Toast.LENGTH_LONG).show()
}
}
fun setData(tank: Tank?, position: Int) {
itemView.txvTankName.text = tank!!.tank_name
itemView.txvTankCapacity.text = tank!!.tank_capacity
itemView.txvTankType.text = tank!!.tank_type
this.currentTank = tank
this.currentPosition = position
}
}
}
And here a screen of of android studio:
Android Studio problem
What am I doing wrong?
Try as follow
import ...
//use your context as member of your class put private as modifier
class TankAdapter(private val context: Context, val tanks: List<Tank>) : RecyclerView.Adapter<TankAdapter.ViewHolder>() {
...
inner class ViewHolder(itemview: View) : RecyclerView.ViewHolder(itemview) {
...
init {
itemView.setOnClickListener {
...
//call startActivity from context
context.startActivity(intent)
}
...
}
...
}
}
I want to know how to clear the webview's content just by clicking on a button with javaFX? So how I can do that? For example: WebView1 contains google web page while clicking on a button should this page clear
You can clear the web view by loading some empty content:
webView.getEngine().loadContent("");
Complete example:
import java.util.regex.Pattern;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class WebBrowser extends Application {
private TextField textField ;
private WebView webView ;
#Override
public void start(Stage primaryStage) {
webView = new WebView();
textField = new TextField("https://www.google.com");
textField.setOnAction(e -> load());
load();
Button clearButton = new Button("Clear");
clearButton.setOnAction(e -> webView.getEngine().loadContent(""));
BorderPane root = new BorderPane(webView, new HBox(10, textField, clearButton), null, null, null);
textField.setPadding(new Insets(5));
root.setPadding(new Insets(5));
Scene scene = new Scene(root, 800, 600);
primaryStage.setScene(scene);
primaryStage.show();
}
private void load() {
String url = makeUrl(textField.getText()) ;
webView.getEngine().load(url);
textField.setText(url);
}
private String makeUrl(String text) {
if (Pattern.matches("[a-zA-Z]+:.+", text)) {
return text ;
} else return "http://"+text ;
}
public static void main(String[] args) {
launch(args);
}
}
I am new on J2me developer using LWUIT library. I am making two forms: one is MainMidlet.java and another is UpgradeApp.java. Problem is that whatever the component add on UpgradeApp.java the component are not displayed. Please help me.
My Code as Follows.
MainMidlet.java
package com.sun.lwuit.jewelvicinity;
import com.sun.lwuit.Button;
import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.Dialog;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.FlowLayout;
import com.sun.lwuit.layouts.GridLayout;
import com.sun.lwuit.plaf.UIManager;
import com.sun.lwuit.table.TableLayout.Constraint;
import com.sun.lwuit.util.Resources;
import java.io.IOException;
import javax.microedition.midlet.*;
public class MainMidlet extends MIDlet implements ActionListener
{
Form frm_Main;
public Button btn_main_Search, btn_main_WishList, btn_main_UpgradeApp, btn_main_Login, btn_main_NewUser,btn_main_Help, btn_main_AboutUs, btn_main_ContactUs, btn_main_Feedback, btn_main_Terms,btn_main_Privacy, btn_main_Exit;
public Image img_main_Search, img_main_Wishlist, img_main_UpgradeApp, img_main_Login, img_main_NewUser,img_main_Help, img_main_AboutUs, img_main_ContactUs, img_main_FeedBack, img_main_Terms,img_main_Privacy, img_main_Exit;
public Command cmd_Exit, cmd_Select;
public void startApp()
{
//--- Use for third soft Button
//Display.getInstance().setThirdSoftButton(true);
Display.init(this);
try
{
Resources theme = Resources.open("/LWUITtheme.res");
UIManager.getInstance().setThemeProps(theme.getTheme(theme.getThemeResourceNames()[0]));
}
catch (IOException io)
{
io.printStackTrace();
Dialog.show("Theme Exception", io.getMessage(), "Ok", null);
}
frm_Main = new Form("Jewel Vicinity");
try
{
img_main_Search = Image.createImage("/res/btn_main_search.png");
img_main_Wishlist = Image.createImage("/res/btn_main_wishlist.png");
img_main_UpgradeApp = Image.createImage("/res/btn_main_upgradeapp.png");
img_main_Login = Image.createImage("/res/btn_main_login.png");
img_main_NewUser = Image.createImage("/res/btn_main_newuser.png");
img_main_Help = Image.createImage("/res/btn_main_help.png");
img_main_AboutUs = Image.createImage("/res/btn_main_aboutus.png");
img_main_ContactUs = Image.createImage("/res/btn_main_contactus.png");
img_main_FeedBack = Image.createImage("/res/btn_main_feedback.png");
img_main_Terms = Image.createImage("/res/btn_main_terms.png");
img_main_Privacy = Image.createImage("/res/btn_main_privacy.png");
img_main_Exit = Image.createImage("/res/btn_main_exit.png");
}
catch (IOException io)
{
io.printStackTrace();
Dialog.show("Image not Found!", io.getMessage(), "Ok", null);
}
btn_main_Search = new Button("Search", img_main_Search);
btn_main_WishList = new Button("Wish List", img_main_Wishlist);
btn_main_UpgradeApp = new Button("Upgrade", img_main_UpgradeApp);
btn_main_Login = new Button("Login", img_main_Login);
btn_main_NewUser = new Button("NewUser", img_main_NewUser);
btn_main_Help = new Button("help", img_main_Help);
btn_main_AboutUs = new Button("About Us", img_main_AboutUs);
btn_main_ContactUs = new Button("Contact Us", img_main_ContactUs);
btn_main_Feedback = new Button("FeedBack", img_main_FeedBack);
btn_main_Privacy = new Button("Privacy", img_main_Privacy);
btn_main_Terms = new Button("Terms", img_main_Terms);
btn_main_Exit = new Button("Exit", img_main_Exit);
lbl_main_WishList.setTextPosition(Component.BOTTOM);
lbl_main_WishList.setAlignment(Component.CENTER);
lbl_main_WishList.getStyle().setMargin(0, 30, 0, 30);
lbl_main_UpgradeApp = new Label("Upgrade");
cmd_Exit = new Command("Exit", 1);
cmd_Select = new Command("Select");
GridLayout grd_MenuLayout = new GridLayout(4, 3);
frm_Main.setTitle("Menu");
frm_Main.setLayout(grd_MenuLayout);
frm_Main.setScrollableY(true);
//---- Add Button On Main Form
frm_Main.addComponent(btn_main_Search);
frm_Main.addComponent(btn_main_WishList);
frm_Main.addComponent(btn_main_UpgradeApp);
frm_Main.addComponent(btn_main_Login);
frm_Main.addComponent(btn_main_NewUser);
frm_Main.addComponent(btn_main_Help);
frm_Main.addComponent(btn_main_AboutUs);
frm_Main.addComponent(btn_main_ContactUs);
frm_Main.addComponent(btn_main_Feedback);
frm_Main.addComponent(btn_main_Terms);
frm_Main.addComponent(btn_main_Privacy);
frm_Main.addComponent(btn_main_Exit);
frm_Main.addCommand(cmd_Select);
frm_Main.addCommand(cmd_Exit);
//frm_Main.setCommandListener(this);
frm_Main.addCommandListener(this);
frm_Main.show();
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void actionPerformed(ActionEvent ae)
{
Command cmd = ae.getCommand();
String strcmdName = cmd.getCommandName();
if(strcmdName.equals("Exit"))
{
notifyDestroyed();
}
if (strcmdName.equals("Select"))
{
if(btn_main_Search.hasFocus())
{
//Dialog.show("Search", "Search", "Ok", null);
Form frm_Search = new Form("Search");
frm_Search.show();
}
if(btn_main_UpgradeApp.hasFocus())
{
Form UpgradeApp = new Form("Upgrade App");
UpgradeApp.show();
}
}
}
}
UpgradeApp.java
package com.sun.lwuit.jewelvicinity;
import com.sun.lwuit.Command;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.Label;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.FlowLayout;
public class UpgradeApp extends Form implements ActionListener
{
Label lbl_UpgradeApp;
Command cmd_Yes, cmd_No;
Form frm_UpgradeApp;
public UpgradeApp()
{
Display.init(this);
frm_UpgradeApp = new Form("Upgrade Application");
lbl_UpgradeApp = new Label("The New Version of Jewel.");
cmd_Yes = new Command("Yes", 1);
cmd_No = new Command("No", 2);
FlowLayout flw_UpgradeLayout = new FlowLayout(CENTER);
frm_UpgradeApp.setLayout(flw_UpgradeLayout);
frm_UpgradeApp.addComponent(lbl_UpgradeApp);
frm_UpgradeApp.addCommand(cmd_No);
frm_UpgradeApp.addCommand(cmd_Yes);
frm_UpgradeApp.addCommandListener(this);
frm_UpgradeApp.setVisible(true);
frm_UpgradeApp.show();
}
public void actionPerformed(ActionEvent evt)
{
}
}
From a brief review you seem to be calling Display.init(this); in a form subclass. I suggest you use a debugger and walk through the code.